Randomization Services Reference
Randomization Services is an API that generates cryptographically secure random numbers.
-
Generates an array of cryptographically secure random bytes.
Declaration
Swift
func SecRandomCopyBytes(_rnd: SecRandomRef, _count: Int, _bytes: UnsafeMutablePointer<UInt8>) -> Int32Objective-C
int SecRandomCopyBytes ( SecRandomRef rnd, size_t count, uint8_t *bytes );Parameters
rndThe random number generator object to use. Specify
kSecRandomDefaultto use the default random number generator.countThe number of random bytes to return in the array pointed to by the
bytesparameter.bytesThe random bytes generated by the function.
Return Value
Returns
0if the function completed successfully and-1if there was an error. Check theerrnosystem variable for the error.Discussion
This function reads from
/dev/randomto obtain an array of cryptographically-secure random bytes. For more information on the/dev/randomrandom-number generator, see the manual page for random(4).Availability
Available in iOS 2.0 and later.
-
Abstract Core Foundation-type object containing information about a random number generator.
Declaration
Swift
typealias SecRandomRef = COpaquePointerObjective-C
typedef const struct __SecRandom * SecRandomRef;Import Statement
Objective-C
@import Security;Swift
import SecurityAvailability
Available in iOS 2.0 and later.
-
Indicates the default random number generator.
Declaration
Swift
let kSecRandomDefault: SecRandomRefObjective-C
const SecRandomRef kSecRandomDefault;Constants
-
kSecRandomDefaultkSecRandomDefaultWhen passed to the
SecRandomCopyBytesfunction as the random number generator reference, this constant indicates that the default number generator should be used.This constant is a synonym for
NULL.Available in iOS 2.0 and later.
-
Copyright © 2016 Apple Inc. All rights reserved. Terms of Use | Privacy Policy | Updated: 2013-09-18
