在VBA中重复随机数字

我在VBA中有一个蒙特卡洛模拟。 客户希望(不要质疑为什么)修复随机数字序列,即每次运行模型时,序列应保持不变。 我设法修复这里描述的随机种子。 但在不同的电脑上不一样。 任何想法为什么以及如何在不同的机器上修复它?

您可以使用带有负参数的rnd函数来获得随机数的重复列表。

这是一个链接到文档:

http://office.microsoft.com/en-us/access-help/rnd-function-HA001228901.aspx

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.


 Sub TestRandomNumberSequence() rnd (-10) For i = 1 To 5 Randomize 10 MsgBox BetweenRange(1, 20, rnd) Next i 'always returns the following sequence '5 '18 '19 '6 '17 End Sub Function BetweenRange(min As Integer, max As Integer, ByVal rnd As Double) As Integer BetweenRange = Int((max - min + 1) * rnd + min) End Function 

根据您的要求,请检查以下链接:

Wabash学院下载