Page 1 of 1

"reproducible randomizing" - any good ways?

Posted: Sat Feb 09, 2008 2:56 pm
by muszek
The problem: I have some parameter, a seed (say it's user ID) and want to generate a list of random numbers withing some range, but I'd also like to be able to regenerate that list in the future.

Example: I have users. Every user has a building. I have prepared X different images of windows (win1.png, win2.png ... winX.png) and want to generate a random list of those images (say list contains 100 elements, but it's not important), but be able to reproduce this list in the future. So: every user's building looks different, but when I reload the page of a particular user (say John, user_id=4), it will look the same as before.

Another requirements:
* every image has about the same chance of appearing, so that win1.png isn't used much more often than win40.png
* I'd like to be able to change X (and I'm fine with lists being different then before... so when I add 10 new windows to choose from, John's building won't look anything like before).

Are there any common ways of doing this? I could come up with some algorithm myself, but I'm sure others have done some efficient methods of achieving this result.

thanks in advance,
muszek

Re: "reproducible randomizing" - any good ways?

Posted: Sat Feb 09, 2008 3:02 pm
by Weirdan
for random generator to produce identical sequences you have to seed it with a constant value (userid for example). This code will produce identical sequence every time it's ran:

Code: Select all

 
srand(1);  // seed the random number generator with a constant
echo rand() . "\n"; 
echo rand() . "\n"; 
echo rand() . "\n";
 

Re: "reproducible randomizing" - any good ways?

Posted: Sat Feb 09, 2008 3:09 pm
by muszek
thank you :)

Re: "reproducible randomizing" - any good ways?

Posted: Fri May 02, 2008 1:24 am
by geethalakshmi
Hi,
below is the link which might be useful to you.
http://hiox.org/index.php?id=262