|
-
Feb 17th, 2000, 11:45 PM
#1
Thread Starter
New Member
How do you generate a random number?
------------------
//R//A//Y//
///L///I///
-
Feb 18th, 2000, 02:41 AM
#2
PowerPoster
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
-
------------------
[email protected]
...
Every program can be reduced to one instruction which doesn't work.
-
Feb 18th, 2000, 09:56 AM
#3
Lively Member
Here is how to make a true interger random number:
randomize
int((UBOUND - LBOUND + 1) * rnd + LBOUND)
------------------
Website
-
Feb 19th, 2000, 06:39 AM
#4
Thread Starter
New Member
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///
-
Feb 20th, 2000, 01:50 AM
#5
PowerPoster
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
-
------------------
[email protected]
...
Every program can be reduced to one instruction which doesn't work.
-
Feb 20th, 2000, 05:30 AM
#6
PowerPoster
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.
------------------
[email protected]
...
Every program can be reduced to one instruction which doesn't work.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|