|
|
◆ Erand48()
| Function Erand48 |
( |
Xseed() As |
Integer | ) |
|
区間[0,1)の48ビット実数乱数 (線形合同法)
- 目的
- 線形合同法により[0,1)の48ビット実数乱数を生成する.
- 戻り値
- Double
生成された[0,1)の48ビット実数乱数.
- 引数
-
| [in,out] | Xseed() | 配列 Xseed(2)
[in] 48ビット(16ビット×3)のシード.
[out] 更新された48ビット(16ビット×3)のシード. |
- 使用例
- [0, 1)の実数の乱数を10個生成する. Seed48を使用して初期化したDrand48と, Xseed()に同じシード値を設定したErand48は同じ乱数系列を生成する.
Sub Ex_Erand48()
Dim XSeed(2) As Integer, Seed As Long, I As Integer
Seed = 13
XSeed(0) = &H330E: XSeed(1) = Seed Mod (2 ^ 16): XSeed(2) = Seed / (2 ^ 16)
Call Seed48(XSeed())
Debug.Print "Drand48"
For I = 1 To 10
Debug.Print Drand48()
Next
Debug.Print "Erand48"
For I = 1 To 10
Debug.Print Erand48(XSeed())
Next
End Sub
- 実行結果
0.49125804875894
0.909578015652613
0.696163968687085
0.922235667562695
0.42372016481848
0.593378755016587
0.1323338794958
0.45044780014458
0.269613809642042
0.820416114584759
0.49125804875894
0.909578015652613
0.696163968687085
0.922235667562695
0.42372016481848
0.593378755016587
0.1323338794958
0.45044780014458
0.269613809642042
0.820416114584759
Function Erand48(Xseed() As Integer) As Double 区間[0,1)の48ビット実数乱数 (線形合同法)
Function Drand48() As Double 区間[0,1)の48ビット実数乱数 (線形合同法)
|