Random Numbers

BlitzMax Forums/BlitzMax Beginners Area/Random Numbers

Bill246(Posted 2010) [#1]
I'm trying to generate a simple random number, but I keep getting the same number over and over again. Here's the code I use:

Global X:Int
X = Rand(1,6)
Print X

Every time I run it X gets a value of 3. When I use Rand(1,50), I get a value of 21. I looked at several tutorials on-line and I think I'm following their examples correctly. Am I missing something?

Thanks.


TaskMaster(Posted 2010) [#2]
You need to seed the random number generator with the seedrnd() function.


Czar Flavius(Posted 2010) [#3]
SeedRnd Millisecs() should do the trick.


Dezzo(Posted 2010) [#4]
SeedRnd MilliSecs ()

Some time ago I quickly did a small Random Number Programm for my Visuals. It switches between 0 and 1 and displays them thru the X and Y Axis. Iīve added a Colortable so each Number changes randomly thru one of itīs predefined Colors. Kinda cheap Matrix like........