1 /* Copyright (c) 1998,2011,2014 Apple Inc. All Rights Reserved.
3 * NOTICE: USE OF THE MATERIALS ACCOMPANYING THIS NOTICE IS SUBJECT
4 * TO THE TERMS OF THE SIGNED "FAST ELLIPTIC ENCRYPTION (FEE) REFERENCE
5 * SOURCE CODE EVALUATION AGREEMENT" BETWEEN APPLE, INC. AND THE
6 * ORIGINAL LICENSEE THAT OBTAINED THESE MATERIALS FROM APPLE,
7 * INC. ANY USE OF THESE MATERIALS NOT PERMITTED BY SUCH AGREEMENT WILL
8 * EXPOSE YOU TO LIABILITY.
9 ***************************************************************************
11 * NSRandomNumberGenerator.m
16 * Rewrote using feeRandom module.
17 * ?? 96 Blaine Garst at NeXT
22 * Note: out _priv ivar is actually a feeRand pointer.
25 #import <Foundation/Foundation.h>
26 #import "NSRandomNumberGenerator.h"
30 @implementation NSRandomNumberGenerator
35 _priv = feeRandAlloc();
38 * else no need to re-init
43 - initWithSeed:(unsigned)seed
47 * Free & re-init to use new seed
51 _priv = feeRandAllocWithSeed(seed);
55 - (unsigned)nextNumber
60 return feeRandNextNum(_priv);
63 - (unsigned)nextNumberInRange:(NSRange)range
68 return range.location + ([self nextNumber] % range.length);
71 - (NSData *)randomDataWithLength:(unsigned)l
79 feeRandBytes(_priv, cp, l);
80 return [NSData dataWithBytesNoCopy:cp length:l];