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.

DarkBASIC Discussion / Random number Gernerator help

Author
Message
jkfde
9
Years of Service
User Offline
Joined: 6th Nov 2010
Location:
Posted: 18th Nov 2010 05:27
Hi i want the Random Number Generator to only give back one number
When i type rnd(4) it keeps listing numbers

is there a way to make it so it pick 1 number between 0 and 4 at random.
Libervurto
14
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 18th Nov 2010 14:59
You must be calling rnd more than once to get a list of numbers. It should be obvious that calling rnd before the main loop would only generate one random number. You are aware that you can store the output of rnd in a variable? I.E.
num = rnd(4)

If you want the random number generator to produce the same numbers every time, you can seed the RNG with randomize n, n being any integer. If you seed the RNG like this, every time you run the program you will get the same sequence of random numbers. Most people assign the output of the cpu clock to randomize, randomize timer(), because the clock is always changing it ensures the random numbers are different every time the program is executed.


Do oranges know what colour they are?
Red Eye
11
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 18th Nov 2010 15:48
Altough you can get pretty damn close to "randomness" it isnt random.

http://en.wikipedia.org/wiki/Random_number_generation

Pretty much interesting to read.

Libervurto
14
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 18th Nov 2010 16:56
I don't believe true randomness exists, everything has some sort of input that alters the outcome, no matter how minuscule.


Do oranges know what colour they are?

Login to post a reply

Server time is: 2020-08-12 01:47:35
Your offset time is: 2020-08-12 01:47:35