作业帮 > 英语 > 作业

vb中个随机选取一个0到1000之间的数怎么写

来源:学生作业帮 编辑:搜狗做题网作业帮 分类:英语作业 时间:2024/06/28 21:20:25
vb中个随机选取一个0到1000之间的数怎么写
是x=Rnd*1000还是x=Rnd*1000+1
vb中个随机选取一个0到1000之间的数怎么写
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.