Subject:
|
Re: Programming the RCX in VB
|
Newsgroups:
|
lugnet.robotics
|
Date:
|
Sun, 3 Jan 1999 00:39:40 GMT
|
Viewed:
|
1447 times
|
| |
| |
John,
here is an example how to create random numbers in VB. In the example below
it will generate values between 1 and 6. The statement "Randomize" is
initializing the Random Generator. The function "Rnd" is then used to get
the random numbers.
Dim IntVal as Integer
Randomize 'Initializes the random generator using the
timer
IntVal = Int((6 * Rnd) + 1) ' Generate random value between 1 and 6.
To produce random integers in a given range, use this formula:
Int((upperbound - lowerbound + 1) * Rnd + lowerbound). So in your example it
has to look like:
IntVal = Int((25 - 5 + 1) * Rnd + 5)
I hope that helps.
Juergen
JohnC wrote in message ...
> I'm starting on the program for my Mindstorms robot and I had a question.
> What is the best way to get a random number using VB? At first glance I can
> find a register that appears to generate a random number between 1 and 32768,
> but how do I limit this range? How do I [easily] get a random number between,
> say, 5 and 25?
>
> Also, has anyone posted VB source code (with comments) either here or on a
> website somewhere? That would be a big help to those of us who are just
> getting started...
>
> Thanks!
>
> -- John
|
|
Message is in Reply To:
| | Programming the RCX in VB
|
| I'm starting on the program for my Mindstorms robot and I had a question. What is the best way to get a random number using VB? At first glance I can find a register that appears to generate a random number between 1 and 32768, but how do I limit (...) (26 years ago, 2-Jan-99, to lugnet.robotics)
|
2 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
Active threads in Robotics
|
|
|
|