Page 1 of 1
random seeds ?
Posted: Thu May 15, 2008 2:46 am
by jph_wacheski
how are random(x,v) numbers seeded ?
In my Artificial Nature entry to the TIGsource procedural compo. ;
http://forums.tigsource.com/index.php?topic=1696.0
I have noticed that the random level starts the same each and every time.., just wondering what is used as the random seed ? the app. time ?? as if you press space (the app.state is just re-initiated) the whole play field is randomized,. it would perhpas be some times usefull to get the same random patterns,. could be good to let the designer set the random seed for the random functions. . ,
Posted: Thu May 15, 2008 10:35 am
by Kjell
Hi jph,
I noticed this as well in my "walking legs example" posted in the Tips'n'Tricks section. Each clone uses a rnd() seed to offset their animation, however .. this number seems to remain the exact same for each of the clones every time the build is ran. Within the editor it does seem to differ every time though
K
Posted: Thu May 15, 2008 10:59 am
by VilleK
I need to check how this is done. Perhaps add a setSeed-function or similar. I think the random-seed is initiated to the same value every time a application starts, and this is how it should be inside the designer too, although currently it is not.
Jph, the screen shots on tigsource look impressive but I couldn't download the latest version, I guess it is because I'm not registered on tigsource.
Btw, Kjell those walking legs are really cool looking. And I've used your logo on the forum, hope that is ok with you

work around,. found!
Posted: Sat May 17, 2008 1:54 am
by jph_wacheski
I found a very simple way around the random seed being the same at startup,.
I just moved my object spawning from the onStart event to a timer in the onUpdate,. and then by adding a random interval to the timer we get sweet random levels in my procedural game!
Code: Select all
randomizr.interval=random(.2,.18);
looks to be workin'
just for you Ville here is an early ver. of my entry,. not much of a 'game' just yet,. wait for it!
Posted: Tue May 27, 2008 8:43 pm
by kattle87
Actually I think there's a little problematic part with setRandomSeed(); It's not a bug but I started thinking we have got nothing to use as a seed which is external to the application! We need a property like "App.Now" that should return current time (or better current date + time) in seconds to be used inside setRandomSeed().
The only other way to get random seeds seems to be relying on machine imperfection using (setRandomSeed(App.Time * 10000)) inside a timer to get something working;
Last chance: imagine that if you call setRandomSeed(0) you get the current time set as seed and this should be easier to implement but I'm scared about the growing dimension of the executable
jph_wacheski prove me wrong but it seems to me your trick does not work anymore! I always get the lower possible value when using random(base, variance) function, unless I do not set the Seed;
EDIT: found this!
http://www.midnightbeach.com/rdtsc.html or this
http://en.wikipedia.org/wiki/RDTSC
You just need some assembler lines (already implemented in delphi in the examples) to get this working and get an ALMOST completely random seed

hope you found it usefull! Bye bye!
Posted: Tue May 27, 2008 8:58 pm
by jph_wacheski
yes. I am not really sure how the setRandomSeed(n); function is working just yet,. I asked Ville in the releases thread,. but haven't heard anything,. I had actually abandonded that game I had started for tha compo,. as it was grid based, and I was haveing problems keeping things aligned with out rounding functions,. so now that we have floor() and ceil() I may get back to that first attempt,. . only now the new game is keeping me busy,. so we'll see.
the simplest way I can figured to get actually random seeds is to just start a timer and have the player "press a key" to "continue" or "set the seed",. and this way they will always have a random reaction time,. as ppl are not computers,. . and therefor more prone to randomness.. ,
Posted: Wed May 28, 2008 7:06 am
by VilleK
setRandomSeed can be used to make sure random behaves the same every time. If you use the random function to generate levels in a game and you want the levels to look the same every time you can use something like setRandomSeed(LevelNr) before generating walls, enemies etc.
It is true that it is hard to find a "random" value to set with setRandomSeed. But like jph suggest most games will have a title screen so when the user press a key you can use app.time. Passing 0 as a parameter to let zge choose a random value is a good idea. App.TimeOfDay/Now is also a good variant, that could perhaps be useful for other stuff. Finally you can try to make a random value by combining several variables that are likely to have variance in them like "App.DeltaTime + App.MousePosition.X + App.MousePosition.Y".