Post Reply 
(32S) Random Number Utilities
10-23-2022, 03:21 PM
Post: #1
(32S) Random Number Utilities
Note: The following programs should work with the original HP 32S. The checksums listed are for the HP 32SII only.


HP 32SII Program: Fill a Set of Registers with Increasing Integers

This program fills up the alpha registers with consecutive increasing integers. Up to 25 slots are available, A- Y, with the lowest being stored in A. Register Z is used to store the difference.

The difference from both numbers should not be more than 24.

Code:
F01  LBL F
F02  x<>y
F03  1
F04  -
F05 STO Z
F06 -
F07 STO i
I01  LBL I
I02  RCL i
I03  IP
I04  RCL+ Z
I05  STO(i)
I06  DSE i
I07  GTO I
I08  RTN

F: 10.5 bytes, 32SII checksum 9FB9
I: 12.0 bytes, 32SII checksum E189
Total: 22.5 bytes

Examples

18 to 27: 18 ENTER 27 XEQ F
Results:
A = 18, B = 19, C = 20, D = 21, E = 22,
F = 23, G = 24, H = 25, I = 26, J = 27


HP 32SII Program: Pick from Registers A through Y

Enter the number of registers to pick from into register Z. For example, if you have registers A through J loaded, store 10 into register Z.

Note: When used for indirect addressing, the absolute value of integer of register i is used. This will allows us to save a few steps.

Code:
G01  RANDOM
G02  RCL× Z
G03  1
G04  +
G05  STO i
G06  RCL(i)
G07  RTN

G: 12.0 bytes, 32SII checksum FE18

Example:

Use the data from the last problem.

10 STO Z,
XEQ G: 22
XEQ G: 21
(results will vary)



Source for the next two programs:

Chamberlain, Gary. "HP-29C Random Number Generators" PPC Journal V6 N7 October 1979

HP 32SII Program: Uniform Distribution

This program picks random numbers between two parameters.

Code:
U01  LBL U
U02  STO C
U03  -
U04  STO D
W01  LBL W
W02  RANDOM
W03  RCL× D
W04  RCL+ C
W05  STOP
W06  GTO W

U: 6.0 bytes, 32SII checksum 8022
W: 9.0 bytes, 32SII checksum 88EE
Total: 15.0 bytes

Example:

Random numbers between -1 and 1:

XEQ U: -0.74076 (press R/S for more random numbers)
0.28000
-0.80090
0.20653
0.50614


HP 32SII Program: Gaussian Distribution of Random Numbers

Generate random numbers that fit on a normal distribution with mean M and deviation D. Two random numbers are generated, press x<>y to see both results.

Code:
X01  LBL X
X02  INPUT M
X03  INPUT D
X04  RAD   (radians mode)
Y01  LBL Y
Y02  RANDOM 
Y03  2 
Y04  ×
Y05  π
Y06  ×
Y07  RANDOM
Y08  LN
Y09  -2
Y10  ×
Y11 SQRT
Y12  θ,r→y,x
Y13  RCL× D
Y14  RCL+ M
Y15  x<>y
Y16  RCL× D
Y17  RCL+ M
Y18  STOP
Y19  GTO Y

Example:

Mean = 3
Deviation: 1.5

XEQ X
M? 3 R/S
D? 1.5 R/S

1.70434 x<>y 2.89313 R/S
2.22287 x<>y 2.50113 R/S
1.67644 x<>y 2.87034 ...
(results will vary)
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)