FROM : James Robinson
DATE : Fri Jan 10 11:23:02 2003
On Fri, 10 Jan 2003, iUNI Technologies Corp. wrote:
> srandom(45);
This seeds the pseudo-random number generator with the same number every
time, resulting in the same pseudo-random sequence every time. This is a
feature (think debugging).
> float randValue = ((float) random() / (float) RAND_MAX);
Cast to double.
> NSNumber *myRand = [[NSNumber alloc] initWithInt:((randValue)+40)];
> [sdata appendString:[myRand stringValue]];
> [myRand release];
Use:
srandom(time(NULL));
time(NULL) returns the current system time in seconds, which is unlikely
to be the same twice.
Also, the standard C calls are srand() and rand() (in <stdlib.h>).
srandom() and random() are UNIX-specific, but they can be higher quality.
Which you use depends on how important portability is to you.
Hope this helps,
--
James
DATE : Fri Jan 10 11:23:02 2003
On Fri, 10 Jan 2003, iUNI Technologies Corp. wrote:
> srandom(45);
This seeds the pseudo-random number generator with the same number every
time, resulting in the same pseudo-random sequence every time. This is a
feature (think debugging).
> float randValue = ((float) random() / (float) RAND_MAX);
Cast to double.
> NSNumber *myRand = [[NSNumber alloc] initWithInt:((randValue)+40)];
> [sdata appendString:[myRand stringValue]];
> [myRand release];
Use:
srandom(time(NULL));
time(NULL) returns the current system time in seconds, which is unlikely
to be the same twice.
Also, the standard C calls are srand() and rand() (in <stdlib.h>).
srandom() and random() are UNIX-specific, but they can be higher quality.
Which you use depends on how important portability is to you.
Hope this helps,
--
James
| Related mails | Author | Date |
|---|---|---|
| iUNI Technologies… | Jan 10, 11:06 | |
| James Robinson | Jan 10, 11:23 | |
| Jeff Szuhay | Jan 10, 11:31 | |
| Mike Vannorsdel | Jan 10, 11:35 | |
| Timothy J. Wood | Jan 10, 12:42 | |
| iUNI Technologies… | Jan 10, 12:51 | |
| James Robinson | Jan 10, 12:58 | |
| Steve Quirk | Jan 10, 13:02 |






Cocoa mail archive

