HP 12C Random Integer Number Generator

11162017, 04:58 AM
(This post was last modified: 11162017 06:06 AM by Gamo.)
Post: #1




HP 12C Random Integer Number Generator
This program is to generate 6 digits integers for quick pick lottery generator using HP 12C
Using program to calculates uniformly distributed pseudorandom numbers from the HP 12 CP Solution Handbook and added the integer digits that I want. To use this program: [R/S] then GTO18 [R/S] Code:
Example: [R/S] result 0.83 [GTO 18] result 831,051 [R/S] result 0.27 [GTO 18] result 272,860 [R/S] result 0.20 [GTO 18] result 196,339 [R/S] result 0.75 [GTO 18] result 750,082 Is there any better or shorter solution for this kind of random program? Thank You Gamo 

11162017, 08:06 AM
Post: #2




RE: HP 12C Random Integer Number Generator
(11162017 04:58 AM)Gamo Wrote: Is there any better or shorter solution for this kind of random program? This generator r:=frac(997*r) was quite popular in the Seventies as it was fast and short and provided good results. However, some care about the initial seed was required, so some implementations (including yours) set this seed within the program. Which means that the produced number sequence is not random, but the same each time you restart the program. Another wellreputed RNG that was often used in HP programs is r:=frac(9821*r+0,211327). This one is less picky about the initial seed. Simply enter anything between 0 and 1 in R0 and run the program. For many purposes even simpler generators may do. For instance r:=frac[(r+pi)²]. I often used this one in games programs and I had no problems with the results. There was an extensive thread on RNGs last year, related to an translation of HP67 games for the HP41. You will find more information there, including articles in HPrelated papers, discussing different generators. The one mentioned above turned out to be a good choice. Dieter 

11192017, 09:23 PM
(This post was last modified: 11192017 09:41 PM by Dieter.)
Post: #3




RE: HP 12C Random Integer Number Generator
(11162017 04:58 AM)Gamo Wrote: Is there any better or shorter solution for this kind of random program? Gamo, I just noticed that your program ends with a GTO 00. This means that after a random integer has been generated the program will restart at the beginning and so it will produce the same number again... #) I would probably do it some way like this: Code: 01 INTG Initialize: store a random seed between 0 and 1 in R0. Enter a maximum positive integer n and start the program with f[PRGM] [R/S]. The result is a pseudorandom integer between 1 and n. Press [R/S] for more numbers. If a pseudo random number between 0 and 1 is required press [X<>Y]. Example: 0,4711 [STO] 0 999 f[PRGM] [R/S] => 884 [R/S] => 169 [R/S] => 919 The PRNG used here is able to produce one million different results, so n should not be larger than this. Dieter 

11202017, 04:46 AM
(This post was last modified: 11222017 06:08 AM by Gamo.)
Post: #4




RE: HP 12C Random Integer Number Generator
On 11C and 15C both have dedicated RAN# function that very easy to program random 6 digits number using RAN#
Program: Code:
To generate 6 digits random number f USER then press E as many time as you like. Gamo 

11202017, 01:45 PM
(This post was last modified: 11202017 02:13 PM by Dieter.)
Post: #5




RE: HP 12C Random Integer Number Generator
(11202017 04:46 AM)Gamo Wrote: On 11C and 15C both have dedicated RAN# function that very easy to program random 6 digits number using RAN# With a builtin PRNG of course things are easy. However, there is a numeric pitfall. Since the RAN# function may return results as large as 0,9999999999 (i.e. 1–10^{–10}) the intermediate result of r · n may round to n and the final result then is n+1. Example: Suppose you want random numbers between1 and 2000. 0,9999999999 · 2000 + 1 = 2001,000000 Or simply think of generating numbers between 1 and 3, e.g. for a game: 0,9999999999 · 3 + 1 = 4,000000000 This can be avoided by removing the final digit of the random number (and, just to be sure, adding 1 after the INT truncation): Code: RAN# ...or, faster and shorter, simply... Code: RAN# Anyway, the mentioned problem does not occur for your special case n = 999999, so you can leave your program as it is. ;) Also the well known and simple PNRG r := frac[(r+pi)²] is not affected as it generates numbers with (mostly) 8 and (sometimes) 9 decimals on a 10digit calculator. Dieter 

11212017, 05:13 AM
Post: #6




RE: HP 12C Random Integer Number Generator
Thank You Dieter
Very useful information about Random Number Generator Gamo 

11042018, 04:03 PM
Post: #7




RE: HP 12C Random Integer Number Generator
(11162017 04:58 AM)Gamo Wrote: … program is to generate 6 digits integers for quick pick lottery generator using HP 12C … calculates uniformly distributed pseudorandom numbers … added the integer digits that I want. It took a little time to research, but this routine for the Sharp PC1211 from the October 1981 edition of Your Computer (pg.54) matches your range requirement of integers from one to six. [attachment=6553] BEST! SlideRule 

11042018, 06:02 PM
(This post was last modified: 11042018 06:04 PM by Dieter.)
Post: #8




RE: HP 12C Random Integer Number Generator
(11042018 04:03 PM)SlideRule Wrote: It took a little time to research, but this routine for the Sharp PC1211 from the October 1981 edition of Your Computer (pg.54) matches your range requirement of integers from one to six. The relevant part here is not the range of the random integers but the random number generator itself (whose results are then scaled to 1...6). If I understand this correctly, the method is r := frac[ (r+77) · pi^{5} ] Here pi^{5} is 306,0196848 so that before the FRC command the intermediate result is between 23563,5... and 23869,5..., which in turn means that on a 10digit calculator the resulting random number (between 0 and 1) has merely five significant digits. Can someone say something about other properties of this generator? How does it compare to the simple and fast frac[(r+pi)²] generator? Dieter 

« Next Oldest  Next Newest »

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