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

◆ Lcong48()

Sub Lcong48 ( P() As  Integer)

Sets up parameters for random number generators, and initializes seed for Drand48, Lrand48 and Mrand48 (Linear congruential method)

Purpose
This routine sets up parameters for Rand48 series random number generators, and initializes seed for Drand48, Lrand48 and Mrand48.
Parameters
[in]P()Array P(6)
For linear congruential method Xn+1 = (a*Xn + c) mod m, sets up the multiplicand a and the addend c (m (= 2^48) cannot be altered). Also, seed value for Drand48, Lrand48 and Mrand48 is initialized.
  P(0)〜P(2): Seed value
  P(3)〜P(5): multiplicand a. (default = 25214903917)
  P(6): addend c. (default = 11)
Note
The multiplicand a and the addend c, set up by Lcong48(), will be reset to the default values by calling Seed48 or Srand48.
Example Program
Generate 10 real pseudo random numbers in [0, 1). Different random number series is generated from default setting by changing parameters with Lcong48(). Seed48() resets parameters to default setting as well as seed value. The parameters used by Erand48() are also reset by Seed48().
Sub Ex_Lcong48()
Dim P(6) As Integer, XSeed(2) As Integer, Seed As Long, I As Long
Seed = 13
Call Srand48(Seed)
XSeed(0) = &H330E: XSeed(1) = Seed Mod (2 ^ 16): XSeed(2) = Seed / (2 ^ 16)
P(0) = XSeed(0): P(1) = XSeed(1): P(2) = XSeed(2)
P(3) = &HE66D: P(4) = &HDEEC: P(5) = &H15: P(6) = 11 '-- default P(5) = &H5
Call Lcong48(P())
Debug.Print "Parameters changed"
For I = 1 To 10
Debug.Print Drand48(), Erand48(XSeed())
Next
XSeed(0) = &H330E: XSeed(1) = Seed Mod (2 ^ 16): XSeed(2) = Seed / (2 ^ 16)
Call Srand48(Seed)
Debug.Print "Parameters reset"
For I = 1 To 10
Debug.Print Drand48(), Erand48(XSeed())
Next
End Sub
Sub Lcong48(P() As Integer)
Sets up parameters for random number generators, and initializes seed for Drand48,...
Function Erand48(Xseed() As Integer) As Double
48 bit real random number in [0,1) (Linear congruential method)
Sub Srand48(Seed As Long)
Initialization with 32-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
Parameters changed
0.68217601750894 0.68217601750894
3.23807500276132E-02 3.23807500276132E-02
0.923458890562085 0.923458890562085
0.455927073812695 0.455927073812695
0.53016547731848 0.53016547731848
0.513544770641587 0.513544770641587
0.8044530201208 0.8044530201208
0.48267436264458 0.48267436264458
0.100180215892042 0.100180215892042
0.502789161459759 0.502789161459759
Parameters reset
0.49125804875894 0.49125804875894
0.909578015652613 0.909578015652613
0.696163968687085 0.696163968687085
0.922235667562695 0.922235667562695
0.42372016481848 0.42372016481848
0.593378755016587 0.593378755016587
0.1323338794958 0.1323338794958
0.45044780014458 0.45044780014458
0.269613809642042 0.269613809642042
0.820416114584759 0.820416114584759