vb中个随机选取一个0到1000之间的数怎么写是x=Rnd*1000还是x=Rnd*1000+1
来源:学生作业帮助网 编辑:作业帮 时间:2024/08/27 02:41:39
vb中个随机选取一个0到1000之间的数怎么写是x=Rnd*1000还是x=Rnd*1000+1
vb中个随机选取一个0到1000之间的数怎么写
是x=Rnd*1000还是x=Rnd*1000+1
vb中个随机选取一个0到1000之间的数怎么写是x=Rnd*1000还是x=Rnd*1000+1
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.
Rnd Function Example
This example uses the Randomize statement to initialize the random-number generator. Because the number argument has been omitted, Randomize uses the return value from the Timer function as the new seed value.
Dim MyValue
Randomize ' Initialize random-number generator.
MyValue = Int((6 * Rnd) + 1) ' Generate random value between 1 and 6.