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 / Randomizing Numbers

Author
Message
Fantasywiz 54
18
Years of Service
User Offline
Joined: 29th Jun 2006
Location:
Posted: 22nd Mar 2010 09:49
How do I get a random number that is between two different numbers such as 85 and 100?
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 22nd Mar 2010 12:07
Take the difference between them, get a random number between 0 and the difference, i.e., rnd(100 - 85), then add the lower number.

"everyone forgets a semi-colon sometimes." - Phaelax
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 23rd Mar 2010 22:58
RANDOMIZE TIMER()
MyNum = RND(15) + 85


Without the randomize, you'll get the same sequence every time

Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 27th Mar 2010 12:07
The randomize command isn't needed. I believe the random seed is set to the timer automatically.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 27th Mar 2010 12:14
Quote: "The randomize command isn't needed"


True - if you want the same numbers to appear in the same order every time...

TDK

Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 27th Mar 2010 12:21
If I wanted that, I would set the seed to a constant value. I'm saying that the random seed is automatically set to the timer, so randomize timer() is unnecessary.

When I run:

more than once, I do not get the same value. Do you?
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 27th Mar 2010 12:46
Well I never - you are correct Kira so I apologise.

When did that change???

Both BatVink and I are old DB Classic users of many, many years and you always had to use Randomize Timer() or you got the same series of numbers.

If the change to DBPro was announced, I for one certainly missed it!

Ah well - I just learnt something new about DBPro...

TDK

Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 27th Mar 2010 12:57
No harm done

I only just recently learned that variable names aren't case-sensitive in DBPro. Y'know, we all learn all the time.
Indicium
16
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 27th Mar 2010 15:15
Quote: "I only just recently learned that variable names aren't case-sensitive in DBPro. Y'know, we all learn all the time."


You might want to forget that knowledge incase you even move onto a new language, get into the habit early!

Windows 7 32-Bit Home Premium Intel Pentium Dual-Core @ 1.46Ghz 2038mb RAM
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 27th Mar 2010 18:08
Oh I know. That's why it shocked me, because literally all of the other languages I know aren't like that.

But this is getting off topic.

Login to post a reply

Server time is: 2024-11-24 18:02:38
Your offset time is: 2024-11-24 18:02:38