(35S) LCPRNG Programme
|
12-14-2014, 08:29 AM
(This post was last modified: 06-15-2017 01:58 PM by Gene.)
Post: #1
|
|||
|
|||
(35S) LCPRNG Programme
A linear congruential pseudo-random integer generator programme.
The series of integers produced by the expression ( Seed * A + B ) mod M → Seed for constant positive integer values of B, A & M (where the variables may range up to (10^12)-1) can appear random enough for many demands placed on a series of random numbers. To use the programme: 1 Initialize, placing values B A M on the stack & XEQ O017. 2 Set Seed, one positive integer on stack & XEQ O028. 3 XEQ O001 to display the next value in the series & store the value as Seed 4 Either XEQ O001 or actuate R/S to display & seed further values. Uses registers 4 to 7 & variables A, B, C, D, R, Y & Z. (If you’re interested in the internals, lines 31 to 74 find Seed * A mod M, lines 75 to 80 accomplish addition mod M.) 1 LBL O 2 7►I*0 3 RCL+(I) 4 5►I*0 5 RCL+(I) 6 4►I*0 7 RCL+(I) 8 XEQ O031 9 6►I*0 10 RCL+(I) 11 XEQ O075 12 7►I*0 13 + 14 STO (I) 15 STOP 16 GTO O002 17 4►I 18 R↓ 19 REGX►(I) 20 R↓ 21 5►I 22 R↓ 23 REGY►(I) 24 R↓ 25 6►I 26 REGT►(I) 27 RTN 28 7►I 29 REGY►(I) 30 RTN 31 +/- 32 STO B 33 +/- 34 STO A 35 R↓ 36 STO R 37 x<>y 38 REGX 39 1,000,000 40 RMDR 41 STO C 42 - 43 STO D 44 RCL R 45 REGX 46 1,000,000 47 RMDR 48 STO Z 49 - 50 STO Y 51 RCL* D 52 RCL B 53 RMDR 54 RCL Y 55 RCL* C 56 RCL A 57 RMDR 58 + 59 RCL B 60 RMDR 61 RCL D 62 RCL* Z 63 RCL A 64 RMDR 65 + 66 RCL B 67 RMDR 68 RCL Z 69 RCL* C 70 + 71 RCL A 72 RMDR 73 STO R 74 RTN 75 RCL B 76 RMDR 77 + 78 RCL A 79 RMDR 80 RTN |
|||
12-14-2014, 09:58 AM
Post: #2
|
|||
|
|||
RE: HP 35S: LCPRNG Programme
Sorry, line 16 had an error, now corrected ( was X002).
|
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)