Skip to content

Commit

Permalink
Fix EmbeddedApp example
Browse files Browse the repository at this point in the history
  • Loading branch information
kateinoigakukun committed Oct 15, 2024
1 parent 606cb27 commit 85b3479
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,20 @@ func strlen(_ s: UnsafePointer<Int8>) -> Int {
return p - s
}

enum LCG {
static var x: UInt8 = 0
static let a: UInt8 = 0x05
static let c: UInt8 = 0x0b

static func next() -> UInt8 {
x = a &* x &+ c
return x
}
}

@_cdecl("arc4random_buf")
public func arc4random_buf(_ buffer: UnsafeMutableRawPointer, _ size: Int) {
for i in 0..<size {
buffer.storeBytes(of: UInt8.random(in: 0...255), toByteOffset: i, as: UInt8.self)
buffer.storeBytes(of: LCG.next(), toByteOffset: i, as: UInt8.self)
}
}

0 comments on commit 85b3479

Please sign in to comment.