SodiumRandom
struct SodiumRandom
A wrapper for generating random bytes securely.
-
The initializer is disabled.
Declaration
Swift
fileprivate init()
-
Write random bytes into a memory region.
Precondition
0 ≤
sizeInBytes
Declaration
Swift
func bytes(_ pointer: UnsafeMutableRawPointer, sizeInBytes: Int)
Parameters
pointer
A pointer to the memory region.
sizeInBytes
The amount of bytes that should be written.
-
Generate a randomly filled byte array.
Declaration
Swift
func bytes(count: Int) -> Bytes
Parameters
count
The size of the byte array in bytes.
Return Value
The byte array.
-
Generate a random number.
Declaration
Swift
func number() -> UInt32
Return Value
The random number.
-
Generates a random number with uniform distribution.
Declaration
Swift
func uniform(upperBound: UInt32) -> UInt32
Parameters
upperBound
The upper bound.
Return Value
A random number between 0 and
upperBound
.