Simple question about seedRnd

BlitzMax Forums/BlitzMax Beginners Area/Simple question about seedRnd

blackwater(Posted 2011) [#1]
Hi guys, I will be making extensive use of randomly generated numbers using Rnd but my question is how many times do I need to use SeedRnd? Should it only be seeded once the game starts up or before each call to Rnd?


Kirkkaf13(Posted 2011) [#2]
Hi blackwater,

Once you seed rnd is doesn't need seeding again. Therefore only once :).


xcessive(Posted 2011) [#3]
Doing it just the once should do the trick. Each time you seed it, you get a new random number sequence. So seed it every time you need a new sequence. Usually this is at the start of execution. Also I think Blitzmax might automatically seed it at the beginning of run time, but I'm not sure.


Warpy(Posted 2011) [#4]
BlitzMax doesn't automatically seed.


GfK(Posted 2011) [#5]
I use several calls to SeedRnd() - reason being there are points in my game where I need to repeat a fixed set of pseudo-random numbers; each time the player starts a new game, he's given a new random number seed (which is Millisecs()) and that's used to generate all the levels for the game. If I use that seed when the player reloads his game, I can regenerate an identical game to the one he saved - all from a single Int rather than saving masses and masses of game data.

But yep, normally SeedRnd(Millisecs()) at the top of your code is enough.

Last edited 2011


therevills(Posted 2011) [#6]
Well the default seed in Blitzmax is $1234...

random.bmx:
Private
Global	rnd_state=$1234
Const	RND_A=48271,RND_M=2147483647,RND_Q=44488,RND_R=3399
Public


And SeedRnd set rnd_state...

Print RndSeed()


It outputs 4660, which is $1234 :)