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 / rnd command.

Author
Message
Not_Maindric
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Omaha, NE
Posted: 20th Sep 2007 05:57
I decided to do the tutorials, including the things I already know, and doing some I did already, but I figured something about the rnd() command. Not sure if it has been posted before, but each time I make a rnd number, it makes a pattern. Everything I mane a "print rnd(12)" to see what it does, I keep redoing it to see what the result is, "reexicuting the program" and I always get 2.... Dunno why, but it does.

Sinani201
18
Years of Service
User Offline
Joined: 16th Apr 2007
Location: Aperture Science Enrichment Center
Posted: 20th Sep 2007 06:50
use the randomize timer() command before the rnd()

how do you make a sig?
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 20th Sep 2007 11:08
@Maindric

There's really no such thing as a random number when it comes to a computer, but the function RND() simulates it pretty well. Basically, it is an algorithm that calculates a series of numbers based on a seed number. If the seed is the same every time, then the series of numbers will be the same.

Sinani201 sugests that you seed the random number generator with the value of timer(). This is good because it is unlikely to seed the random number generator with the same value because the timer is changing every millisecond.

Sometimes you want the series of numbers to be the same. Perhaps when randomizing a matrix - you always want the same shape, so you would seed rnd with randomize <value> (value always being the same number). Maybe you have a gambling game and you want the computer to win all the time so you always have it deal the same cards or roll the same numbers on the dice - in these cases, you always seed rnd with the same values.

Enjoy your day.
demons breath
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 20th Sep 2007 18:30
Quote: "Maybe you have a gambling game and you want the computer to win all the time so you always have it deal the same cards or roll the same numbers on the dice"


... sounds a bit dodgy to me

I'm never playing cards with you mate

http://jamesmason01.googlepages.com/index.htm
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Not_Maindric
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Omaha, NE
Posted: 21st Sep 2007 02:00
Alright, this makes sense. Thanks, it was just an observation I noticed, and it bugged me...

Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 22nd Sep 2007 10:58
Well, just to clarify. You put..

Randomize Timer()

Just once, at the beginning of your program, and not before all of the Rnd()'s in your program.

This will mean that you do not get any repeating patterns, each time that you run your program.

Login to post a reply

Server time is: 2025-05-31 19:28:36
Your offset time is: 2025-05-31 19:28:36