I am using random number generation as part of a procedure for minimising a function (using the Nelder-Mead simplex algorithm) in objective-c (for iOS). I have used arc4random()
because it seems to be recommended everywhere on the grounds that a) it doesn't need to be seeded and b) it gives higher-quality random numbers than alternatives such as rand() and random()
. I generate doubles between 0 and 1 using
#define ARC4RANDOM_MAX 0x100000000
-(double) Rnd{
return (double)arc4random() / (double)ARC4RANDOM_MAX ; }
However, to test the procedure I need to generate repeatable sequences of random numbers, and I can't find any reference to a way to initialise arc4random()
to do this. Is it the case that arc4random()
cannot be initialised to give a repeatable sequence? If so, how can anyone implement an automated unit test when every test will result in a different answer? Do I need to use the "lower quality" random numbers from random()
? Thanks for your help.