08-07-2014, 03:19 PM
This programs generates random numbers that are from teh Erlang PDF. The program uses the following algorithm:
Given parameters k (integer) and theta
S=0
For i = 1 to k
Generate u=U(0,1)
X = -1/Theta*ln(u)
S = S + X
End
Return S
Memory Map and Flags
R A = Theta
R B = k (integer)
R E = random number seed
R 0 = used
R 1 = S
R 2 = k counter
R I = loop counter
F 0 = When manually set, the program stops after calculating each exponenitally distributed number, after pressing [C]. When cleared, the program proceed in full speed after pressing [C] or after resuming the program by pressing [R/S].
Listing
Usage
1. Enter initial/new random number seed and press [f][E].
2. Enter integer value for k, press [ENTER], enter value for theta, and press [f][A].
3. Enter the number of iterations and press [C]. The program will stop and display the averages for two sample sets. If flag 0 is set, the program will stop after calculating each random number. You must then press [R/S] to resume. You can clear flag 0 and then press [R/S] to resume the program at full speed.
4. Press [R/S] to view the standard deviations for the same two sample sets.
5. (optional) Press [E] to generate a uniform random number.
6. (optional) Press [A] to generate an Erlang random number.
7. (optional) Press [f][C] to generate a sample of 20 Exponenaially distributed random numbers that are store in registers R0 to R9 and Rs0 through Rs9.
Given parameters k (integer) and theta
S=0
For i = 1 to k
Generate u=U(0,1)
X = -1/Theta*ln(u)
S = S + X
End
Return S
Memory Map and Flags
R A = Theta
R B = k (integer)
R E = random number seed
R 0 = used
R 1 = S
R 2 = k counter
R I = loop counter
F 0 = When manually set, the program stops after calculating each exponenitally distributed number, after pressing [C]. When cleared, the program proceed in full speed after pressing [C] or after resuming the program by pressing [R/S].
Listing
Code:
1 LBL e # Store seed
2 STO E
3 RTN
4 LBL E # Calculate uniform random number
5 RCL E
6 PI
7 +
8 5
9 Y^X
10 FRC
11 STO E
12 RTN
13 LBL a
14 STO A # Store theta
15 X<>Y
16 INT # make sure argument is integer
17 STO B # Stoer k
18 RTN
19 LBL A # Calculate one Erlang random number
20 0
21 STO 1 # S = 0
22 RCL B
23 STO 2 # Store loop counter
24 LBL 2 # Start loop
25 GSB E
26 LN
27 CHS
28 RCL A
29 / # calculate X = Exponential random number
30 STO+ 1 # S = S + X
31 1
32 STO- 2 # decrement counter
33 RCL 2
34 x>0? # counter > 0?
35 GTO 2
36 RCL 1 # return s
37 RTN
38 LBL C # Test mean and sdev for Erlang numbers
39 STI # Store number of iterations
40 P<>S
41 0
42 STO 4
43 STO 5
44 STO 6
45 STO 7
46 STO 8
47 STO 9
48 P<>S # Clear stat registers
49 LBL 0
50 RC I
51 PAUSE
52 GSB A
53 STO 0
54 F? 0
55 R/S
56 GSB A
57 F? 0
58 R/S
59 RCL 0
60 Sigma+
61 DSZ
62 GTO 0
63 x-bar # view the averages
64 R/S
65 s # view the standard deviations
66 R/S
67 RCL B
68 RCL A
69 /
70 R/S # display expected mean
71 LAST X
72 /
73 SQRT # display expected standard deviation
74 RTN
75 LBL c # Store a sample of 20 Erlang distributed random numbers
76 1
77 9
78 STI # Store number of iterations
79 LBL 1 # loop to generate and store the first 19 numbers
80 GSB A
81 STO (i)
82 DSZ
83 GTO 1
84 GSB A # Generate and store the 20th random number
85 STO (i)
86 RTN
Usage
1. Enter initial/new random number seed and press [f][E].
2. Enter integer value for k, press [ENTER], enter value for theta, and press [f][A].
3. Enter the number of iterations and press [C]. The program will stop and display the averages for two sample sets. If flag 0 is set, the program will stop after calculating each random number. You must then press [R/S] to resume. You can clear flag 0 and then press [R/S] to resume the program at full speed.
4. Press [R/S] to view the standard deviations for the same two sample sets.
5. (optional) Press [E] to generate a uniform random number.
6. (optional) Press [A] to generate an Erlang random number.
7. (optional) Press [f][C] to generate a sample of 20 Exponenaially distributed random numbers that are store in registers R0 to R9 and Rs0 through Rs9.