我想知道是否有人知道如何将用于随机变量生成的VBA代码转换成Python。 (“Saved”变量是VBA中的布尔值)
function MarsagliaBrayNormSRnd() As Double
Dim U1 As Double, U2 As Double
Dim x As Double, Y As Double
If Saved = False Then
x = 2
While x > 1
U1 = (2 * Rnd() - 1)
U2 = (2 * Rnd() - 1)
x = (U1 * U1) + (U2 * U2)
Wend
Y = Sqr(-2 * Log(x) / x)
MarsagliaBrayNormSRnd = U1 * Y
SavedNormSRnd = U2 * Y
Saved = True
Else
MarsagliaBrayNormSRnd = SavedNormSRnd
Saved = False
End If
End Function
我自己也试过这个代码,但没有成功:
^{pr2}$
不需要在许多其他语言中需要真正可怕的结构!在
相关问题 更多 >
编程相关推荐