SecRandomCopyBytes(_:_:_:)
Generates an array of cryptographically secure random bytes.
Declaration
func SecRandomCopyBytes(_ rnd: SecRandomRef?, _ count: Int, _ bytes: UnsafeMutableRawPointer) -> Int32Parameters
- rnd:
The random number generator object to use. Specify Ksecrandomdefault to use the default random number generator.
- count:
The number of random bytes to return in the array pointed to by the
bytesparameter. - bytes:
A pointer to an array that the function fills with cryptographically secure random bytes. Use an array that is large enough to hold at least
countbytes.
Return Value
A result code set to errSecSuccess or some other value on failure.
Discussion
Always test the returned status to make sure that the array has been updated with new, random data before trying to use the values. For example, to create 10 random bytes: