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 / choosing random numbers?

Author
Message
Acolyte Entertainment
19
Years of Service
User Offline
Joined: 28th Dec 2004
Location: Oregon, US
Posted: 10th Jan 2006 06:57
is it possible to make the engine chose from 10 numbers?
like make it randomly pick between 100,200,300 etc. if so please post how.

thanks,
-Marlin Studios

O
M
G!
The Nerd
20
Years of Service
User Offline
Joined: 5th Jun 2004
Location: Denmark
Posted: 10th Jan 2006 07:20 Edited at: 10th Jan 2006 07:23
Indeed you can

If you're talking about DarkBasic, just do something like this:


the "rnd(10)+1" means that it will pick a number between 0-10. But if you don't want it to pick 0, just put a + 1 after it like I did in the example. Of course you can change the number between the brackets"()" to any number you want.

Hope it helps

-The Nerd

Free Particle Engine for DarkBasic Pro:
http://forum.thegamecreators.com/?m=forum_view&t=60141&b=5
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 10th Jan 2006 10:30
A couple more things:

Always precede your random number code with:

RANDOMIZE TIMER()

This ensures you get different numbers each time the program is run.

Random numbers are always integers from 0 to the number you specify. So, if you want 100,200,300...1000, you would do the following:

MyNum = RND(9) + 1
MyNum = MyNum * 100


Acolyte Entertainment
19
Years of Service
User Offline
Joined: 28th Dec 2004
Location: Oregon, US
Posted: 10th Jan 2006 16:09
thankyou!

O
M
G!
Acolyte Entertainment
19
Years of Service
User Offline
Joined: 28th Dec 2004
Location: Oregon, US
Posted: 10th Jan 2006 16:46
how do you make it chose random words that i decide what the words are?

O
M
G!
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 10th Jan 2006 16:59
You could make an array of words:

Dim MyArray$(3)
MyArray$(1) = "Marlin"
MyArray$(2) = "BatVink"
MyArray$(3) = "The Nerd"


Then, pick a random number:

num = rnd(2) + 1

Then, get the corresponding array element:

PRINT MyArray$(num)

Acolyte Entertainment
19
Years of Service
User Offline
Joined: 28th Dec 2004
Location: Oregon, US
Posted: 11th Jan 2006 01:15
thank you so much! your my hero

O
M
G!

Login to post a reply

Server time is: 2024-09-24 13:23:52
Your offset time is: 2024-09-24 13:23:52