Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Suggestions ➜ Random numbers

Random numbers

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Boris   (9 posts)  Bio
Date Thu 26 Jul 2001 10:09 AM (UTC)
Message
I wouldn't be surprised if this was already on the list... but a scripting function for generating a random number across a given range would be helpful... or does this already exist?
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Fri 27 Jul 2001 03:36 AM (UTC)
Message
There is a VBscript function "rnd" that will return random numbers. Here is some stuff from the manual:

The Rnd function returns a value less than 1 but greater than or equal to 0. The value of number determines how Rnd generates a random number:


  • If number is less than zero Rnd generates the same number every time, using number as the seed.
  • If number is greater than zero Rnd generates the next random number in the sequence.
  • If number is equal to zero Rnd generates the most recently generated number.
  • If number is not supplied Rnd generates the next random number in the sequence.



For any given initial seed, the same number sequence is generated because each successive call to the Rnd function uses the previous number as a seed for the next number in the sequence.

Before calling Rnd, use the Randomize statement without an argument to initialize the random-number generator with a seed based on the system timer.

To produce random integers in a given range, use this formula:



Int((upperbound - lowerbound + 1) * Rnd + lowerbound)


Here, upperbound is the highest number in the range, and lowerbound is the lowest number in the range.





Note To repeat sequences of random numbers, call Rnd with a negative argument immediately before using Randomize with a numeric argument. Using Randomize with the same value for number does not repeat the previous sequence.



- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


12,586 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.