该代码应该在VBA中生成10,000个随机数的序列.出于某种原因,我只能生成一个长度为5842的独特序列,然后重复.但是,这是最奇怪的部分,每次运行代码时,序列都会在不同的地方开始.例如,在一次运行中,元素2660之后的元素与元素8502之后的元素相同(8502-2660 = 5842).下一次运行,我得到一个重复以下元素3704和9546(9546-3704 = 5842)的序列.等等.
Function NormRand() As Double
' NormRand returns a randomly distributed drawing from a
' standard normal distribution i.e. one with:
' Average = 0 and Standard Deviation = 1.0
Dim fac As Double, rsq As Double, v1 As Double, v2 As Double
Static flag As Boolean, gset As Double
' Each pass through the calculation of the routine produces
' two normally-distributed deviates, so we only need to do
' the calculations every other call. …Run Code Online (Sandbox Code Playgroud)