Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will random() ever change?

I have been looking into a development issue that requires the use of pseudorandom number generation to allow the same set of random numbers to be generated for a given seed. I have currently been looking at using long random(void) and void srandom(unsigned seed) for this (man page), and currently these are generating the same set of random numbers in a Mac app, an iOS app and an iOS app (64-bit) which is what I was hoping. The iOS tests were only in the simulator so I don't know whether this will affect the result.

My main concerns is that this algorithm could change at some point, making the applications we're developing effectively useless with old data. What are the chances of these algorithms changing / being different on a future device?

like image 421
Robert Davey Avatar asked Sep 25 '13 07:09

Robert Davey


1 Answers

I'd say it's extremely likely they will change as the sequence is not guaranteed by any standard.

Why not use your own random number sequence? Even a simple linear congruential generator satisfies most statistical properties of randomness. Here is the formula for such a generator:

next_number = (a * current_number + b) % c

with

a = 1103515245
b = 12345
c = 4294967296

These values of a, b, c give you good statistical properties and are quite well known for building quick and dirty generators.

like image 57
Bathsheba Avatar answered Oct 18 '22 00:10

Bathsheba