Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / RND (Is this really random)

Author
Message
Bigdog
21
Years of Service
User Offline
Joined: 28th Apr 2003
Location:
Posted: 28th Apr 2003 23:27
I want to make a random number but when I use the rnd it creates a random number , but each time I load the program after that it is the same random number Try the simple code I have attached and see for yourself. Is there anyway around this because I want a random number to be different each time I play the game I am working on. Thanks
Sephnroth
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 28th Apr 2003 23:46
You need to seed the randomiser - depending on the seed it will generate different values, otherwise it will keep the same pattern indeed. The command you want is Randomize <int> - replace int with an integer value to set as the seed. But if you specify the same integer every time you will end up with the random numbers you generate keeping the same pattern again... so you need an integer that always changes. The internal system timer is a good start ^_~ The command you want there is Timer(), it returns your internal system time in miliseconds, its forver changing. So, before a=rnd(blah), insert this:

randomize timer()

that should work fine (i hope, otherwise i'll look like a moron XD)

Bigdog
21
Years of Service
User Offline
Joined: 28th Apr 2003
Location:
Posted: 28th Apr 2003 23:57 Edited at: 28th Apr 2003 23:57
Thanks that seems to have worked. If anyone else has this trouble I have copied the code to show you how it works in the source code tab.

Login to post a reply

Server time is: 2024-11-24 12:53:05
Your offset time is: 2024-11-24 12:53:05