Friday, August 20, 2010
Generating a Random Number
INT: and Fix remove the fractional part of Number and return the resulting integer value.
difference between INT and Fix is that if Number is a negative, INT will return the first negative integer less than or equal to Number. whereas Fix will return the first negative integer greater than or equal to Number.
eg. INT converts -8.4 to -9
Fix converts -8.4 to -8
http://msdn.microsoft.com/en-us/library/xh29swte(VS.90).aspx
Randomize: uses Number to initialise the Rnd function's random-number generator, giving a new seed value.
omit (leave out) Number, value returned by system timer is used as new seed value.
http://msdn.microsoft.com/en-us/library/8zedbtdt(VS.80).aspx
Rnd: (with no arguments) uses the same number as a seed the first time it is called, then uses the last-generated number a seed value.
returns a value less than 1 but greater than or equal to 0. value of number determines how Rnd generates a randomnumber.
any given initial seed, same number sequence is generated because each successive call to the Rnd function use the previous number as a seed for the next number in the sequence.
http://msdn.microsoft.com/en-us/library/8zedbtdt(VS.80).aspx
http://msdn.microsoft.com/en-us/library/e566zd96(VS.85).aspx
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:
"upperbound" is the highest number in the range, and "lowerbound" is the lowest number in the range.
..as used above.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment