PDA

Click to See Complete Forum and Search --> : Random #


rayli1107
Feb 17th, 2000, 10:45 PM
How do you generate a random number?

------------------
//R//A//Y//
///L///I///

Fox
Feb 18th, 2000, 01:41 AM
You can use the Rnd function to get random numbers (from a lookup table) and randomize them by time with the Randomize function:

-
'This will return the same number every time you restart the project
Print 10 * Rnd


'And this will print true "random" numbers
Randomize
Print 10 * Rnd
-

------------------
fox_mccloud@gmx.net
...
Every program can be reduced to one instruction which doesn't work.

*Super Sniper*
Feb 18th, 2000, 08:56 AM
Here is how to make a true interger random number:

randomize
int((UBOUND - LBOUND + 1) * rnd + LBOUND)

------------------
Website (http://www.kaynor.net)

rayli1107
Feb 19th, 2000, 05:39 AM
Thanks!
1 thing I don't get is that what does the UBOUND and LBOUND mean?
When I try to interpret it, it says that a () is missing.

------------------
//R//A//Y//
///L///I///

Fox
Feb 20th, 2000, 12:50 AM
Well, I didn't try but I don't think that the code'll work. With UBound and LBound you can get the upper and lower count of an array. Example:

-
Dim Temp(10) as Long

Caption = UBound(Temp) 'Returns 10
Caption = LBound(Temp) 'Returns 0
-

------------------
fox_mccloud@gmx.net
...
Every program can be reduced to one instruction which doesn't work.

Fox
Feb 20th, 2000, 04:30 AM
I think what he wanted to show ya is how to generate a random number between some range.

Here's a function you can copy:

-
Function Rand(LVal as Long, UVal as Long)
Randomize
Rand = (UVal - LVal + 1) * Rnd + LVal
End Function
-

Now you can call the function and get a random number between UVal and LVal.

------------------
fox_mccloud@gmx.net
...
Every program can be reduced to one instruction which doesn't work.