small medium large xlarge

11 Nov 2016, 11:46
memetcircus (5 posts)

In page 50, the book gives a code for creating test-data. It uses;

srand48(time(UnsafeMutablePointer(bitPattern: 0))) for seed and it called drand48() to produce non-negative, double-precision, floating-point values, uniformly distributed over the interval [0.0 , 1.0].

My question is why don’t we use srand48(arc4random()) ? Is there a specific reason to use time_t for seed inside stand(48)?

11 Nov 2016, 15:05
Jeff Kelley (8 posts)

Hi! I used time() as that’s what I’ve always seen used for seeding random value-generating code. In this case, since it’s test data, we don’t need to worry about attacks that might guess the random values with a known time value. I don’t see a reason that arc4random() wouldn’t also work. Thanks for the suggestion!

You must be logged in to comment