hp-15c random number simulator

Description

Simulating 15C RAN # on 35s
What are good PRNG for calculators?

This program generates the same values as the hp-15c RAN# function.
There are not enough digits to do this directly so some programming effort is needed to get the right result.
The techniques used here may be of use elsewhere.

Enter a seed in X - only the fractional part is used.
GSB A
A random number matching the hp15c RAN# function is displayed.

Thomas Klemm produced the following formula to allow 15C random number calculations on an HP-42S, which I have coded for that calculator as well.

Seed(n+1) = FRAC(15743.52261*(100000*Seed(n)) + 0.1017980433)
Seed(n+1) is the new random number.

Thomas's program for the hp35S is here.
This code is the basis for the 15C program below.

I have modified the program to produce correct random numbers for all 15C versions including the hp-15c Simulator by Torstan Manz.
Routines D and E provide correct rounding and 10 significant figures.

Seed(n+1) = FRAC(15743.52261*(100000*Seed(n)) + 1.017980433/10)

The last term is modified so all 10 significant digits can be entered.

I have saved several intermediate fractions in memory. The larger fractions are summed. Only the fractional part of this sum is kept. The remaining smaller fractions are then added for a final random number.
The method is similar to that above but it is applied to intermediate fractions in the calculation.

Registers 2, 5, and 7 are added.
Only the fractional part of the sum is kept.
Registers 4 and 6 are then added to this sum to produce the random number.

Using slightly altered seed values from the internal random number generator shows that large random number output changes are generated for small changes in the 10th or 11th digit.
This version of the 15C random number generator appears to be accurate and stable.

There is no particular reason to write this code except as a programming exercise to stress the Simulator and the DM15 during beta testing.

Program Resources

Labels

Name Description
 A Generate random number
 B Sum stored fractions
 C Create fractional parts. Only the fractional sum is kept, then the smaller fractions are added to produce a random number.
 D Trim to 10 digit fractions. 0.4 is added for correct rounding
 E Trim to 5 digit fractions. 0.4 is added for correct rounding
 1 Scale input between 0 and 1

Storage Registers

Name Description
 1 Whole fraction 1
 2 fraction 2
 3 Whole fraction 3
 4 fraction 3 small part
 5 fraction 3 large part
 6 fraction 1 small part
 7 fraction 1 large part

Program

Line Display Key Sequence Line Display Key Sequence Line Display Key Sequence
000 049 36 ENTER 098 5 5
001 42,21,11 f LBL A 050 1 1 099 44,10, 4 STO ÷ 4
002 1 1 051 0 0 100 44,10, 6 STO ÷ 6
003 34 x↔y 052 10 ÷ 101 43 32 g RTN
004 43,30, 9 g TEST x≥y 053 44 3 STO 3 102 42,21,14 f LBL D
005 32 1 GSB 1 054 32 13 GSB C 103 26 EEX
006 1 1 055 32 12 GSB B 104 1 1
007 26 EEX 056 32 14 GSB D 105 0 0
008 5 5 057 43 32 g RTN 106 20 ×
009 20 × 058 42,21,12 f LBL B 107 48 .
010 42 44 f FRAC 059 45 5 RCL 5 108 4 4
011 43 36 g LSTx 060 45 7 RCL 7 109 40 +
012 43 44 g INT 061 45 2 RCL 2 110 43 44 g INT
013 48 . 062 40 + 111 26 EEX
014 5 5 063 40 + 112 1 1
015 2 2 064 42 44 f FRAC 113 0 0
016 2 2 065 45 4 RCL 4 114 10 ÷
017 6 6 066 45 6 RCL 6 115 43 32 g RTN
018 1 1 067 40 + 116 42,21,15 f LBL E
019 20 × 068 42 44 f FRAC 117 26 EEX
020 34 x↔y 069 40 + 118 5 5
021 43 36 g LSTx 070 42 44 f FRAC 119 20 ×
022 34 x↔y 071 43 32 g RTN 120 48 .
023 20 × 072 42,21,13 f LBL C 121 4 4
024 44 1 STO 1 073 45 3 RCL 3 122 40 +
025 43 36 g LSTx 074 26 EEX 123 43 44 g INT
026 1 1 075 5 5 124 26 EEX
027 5 5 076 20 × 125 5 5
028 7 7 077 42 44 f FRAC 126 10 ÷
029 4 4 078 44 4 STO 4 127 43 32 g RTN
030 3 3 079 43 36 g LSTx 128 42,21, 1 f LBL 1
031 20 × 080 43 44 g INT 129 43 13 g LOG
032 43 33 g R⬆ 081 26 EEX 130 42 44 f FRAC
033 40 + 082 5 5 131 1 1
034 32 15 GSB E 083 10 ÷ 132 30
035 42 44 f FRAC 084 44 5 STO 5 133 13 10ˣ
036 44 2 STO 2 085 45 1 RCL 1 134 26 EEX
037 40 + 086 26 EEX 135 9 9
038 1 1 087 5 5 136 20 ×
039 48 . 088 20 × 137 48 .
040 0 0 089 42 44 f FRAC 138 4 4
041 1 1 090 44 6 STO 6 139 40 +
042 7 7 091 43 36 g LSTx 140 43 44 g INT
043 9 9 092 43 44 g INT 141 26 EEX
044 8 8 093 26 EEX 142 9 9
045 0 0 094 5 5 143 10 ÷
046 4 4 095 10 ÷ 144 43 32 g RTN
047 3 3 096 44 7 STO 7
048 3 3 097 26 EEX