The Randomize statement initializes the random number generator. The instruction Int((maxNum – minNum + 1) * Rnd + minNum) uses the Rnd function to generate a random value from the specified minNum to maxNum. The Int function converts the resulting random number to an integer. Instead of assigning constant values for minNum and maxNum, you can use the InputBox function to get these values from the user.
- Randomize
- lucky(t) = Int((maxNum - minNum + 1) * Rnd + minNum)
本文介绍如何使用VBA中的Randomize语句初始化随机数生成器,并通过Int和Rnd函数结合生成指定范围内的随机整数。此外,还展示了如何利用InputBox函数获取用户输入作为随机数的边界。
869

被折叠的 条评论
为什么被折叠?



