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
"reproducible randomizing" - any good ways?
Moderator: General Moderators
Re: "reproducible randomizing" - any good ways?
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";
-
geethalakshmi
- Forum Commoner
- Posts: 31
- Joined: Thu Apr 24, 2008 10:38 pm