Rand() is not Randomizing...

BlitzMax Forums/BlitzMax Beginners Area/Rand() is not Randomizing...

KrayzBlu(Posted 2005) [#1]
There's probably a really simple solution to this that I just haven't found yet, but when I use the Rand() (or Rnd()) command, it gives me the same result. Every time. I even shut down and restarted my computer, still the same result. And its one out of about 10,000. Any help?

Thanks


BlitzSupport(Posted 2005) [#2]
Try adding SeedRnd MilliSecs () to the start of your program.


REDi(Posted 2005) [#3]
KryzBlu, Have a look at the SeedRnd() command.

*EDIT* And BlitzSupport takes the gold! :)


KrayzBlu(Posted 2005) [#4]
:D
Thanks! That worked


boomboommax(Posted 2005) [#5]
it would be better to use the mersenne twist method rather then the inbuilt blitz rand(aka blitz rand sucks)


Warren(Posted 2005) [#6]
In what way is the blitz rand not good enough for 99.999% of users needs?


(tu) ENAY(Posted 2005) [#7]
> In what way is the blitz rand not good enough for 99.999% of users needs?

Well have a try yourself.

Do:

local moo = rand(0,1)


In my experience 0 is often chosen about 60-75% of the time instead of it being 50/50 with 1. Dunno why. Otherdays it's totally different.

But often you have to do extra stuff like this:-

local moo = rand(0,9)

Select moo 
Case 0,2,4,6,8
default
end select


or

local arse:float = rnd(0,1.9999999999)

moo = int(arse)


to make things a bit more random.


Warren(Posted 2005) [#8]
How many samples are you taking? It will average out over an infinite timeline. Or maybe it won't.

See, it's random.


WarpZone(Posted 2005) [#9]
Anybody got a BlitzMax mersenne twist function that they could post here? I left my math degree and kanji charts in my other brain.


boomboommax(Posted 2005) [#10]
er do a search for "mersenne" in these max forums, there is a module


Warren(Posted 2005) [#11]
Interestingly, the only way to evenly distribute Rand(0,1) over any number of samples would require it to return the opposite of the previous sample. Which isn't random at all.