XLPack 7.0
XLPack Numerical Library (Excel VBA) Reference Manual
Loading...
Searching...
No Matches

◆ Drand48()

Function Drand48 ( )

48 bit real random number in [0,1) (Linear congruential method)

Purpose
Generates 48 bit real random number in [0,1) by linear congruential method.
Returns
Double
Generated 48 bit real random number in [0,1).
Example Program
Generate 10 real pseudo random numbers in [0, 1). Same random number series are generated by using Srand48() and Seed48() when equivalent seed values are used.
Sub Ex_Drand48()
Dim XSeed(2) As Integer, Seed As Long, I As Integer
Seed = 13
Call Srand48(Seed)
Debug.Print "Initialized by Srand48"
For I = 1 To 10
Debug.Print Drand48()
Next
Seed = 13
XSeed(0) = &H330E: XSeed(1) = Seed Mod (2 ^ 16): XSeed(2) = Seed / (2 ^ 16)
Call Seed48(XSeed())
Debug.Print "Initialized by Seed48"
For I = 1 To 10
Debug.Print Drand48()
Next
End Sub
Sub Srand48(Seed As Long)
Initialization with 32-bit seed for Drand48, Lrand48 and Mrand48 (Linear congruential method)
Sub Seed48(Xseed() As Integer)
Initialization with 48-bit seed for drand48, lrand48 and mrand48 (Linear congruential method)
Function Drand48() As Double
48 bit real random number in [0,1) (Linear congruential method)
Example Results
Initialized by Srand48
0.49125804875894
0.909578015652613
0.696163968687085
0.922235667562695
0.42372016481848
0.593378755016587
0.1323338794958
0.45044780014458
0.269613809642042
0.820416114584759
Initialized by Seed48
0.49125804875894
0.909578015652613
0.696163968687085
0.922235667562695
0.42372016481848
0.593378755016587
0.1323338794958
0.45044780014458
0.269613809642042
0.820416114584759