Looking for PRNG for HP-34C - Printable Version +- HP Forums (https://archived.hpcalc.org/museumforum) +-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html) +--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html) +--- Thread: Looking for PRNG for HP-34C (/thread-231616.html) |
Looking for PRNG for HP-34C - Dave Boyd - 09-22-2012 I recently got a very pretty HP-34C from the usual place. It works very nicely; apparently the well-known tragic flaws of the series were avoided by previous owners. (I have flat-topped AA NiMHs on the way, which will be externally charged, yes yes.) I immediately started programming it, with my usual first program, a simple dice roller. Alas, though this device is the ancestor of the HP-15C, and has many advanced features, it does not have a RAN# function. (I think the 11C and 15C were the first HPs to have that?) It also does not have the integer math which would allow a Linear Congruential Generator to be implemented; for instance, it lacks the modulo function. So how can we make a good-enough PRNG? I looked through the program library here at the Museum for solutions for such machines as the HP-67. I found something in a game program, where the seed is retrieved from a storage register, muliplied by 997, the integer portion discarded, and the result stored again. I haven't done a lot of analysis but it doesn't appear to give very good results, though they are adequate in the game program. So, can anybody devise a reasonably good floating-point-only PRNG? It should be suitable for at least the 34C. I hesitate to call this a 'challenge', since my solution is not actually mine, and I intend to replace it with whatever anybody comes up with that's better. It should give a number >= 0, and less than 1. It should have results similar to rolling an unbiased 10^9-sided die, with as many digits as possible, and as long a period as possible, though if the only the first four or so digits are suitable that's OK. Naturally, it should use as few steps and registers as possible.
Thanks for considering... Edited: 22 Sept 2012, 2:31 a.m.
Re: Looking for PRNG for HP-34C - Massimo Gnerucci (Italy) - 09-22-2012 I remember using xn+1 = FRC ( 9821 xn + 0.211327 ) on all of my 41C*
Edited: 22 Sept 2012, 5:55 a.m.
Re: Looking for PRNG for HP-34C - Dieter - 09-22-2012 For the record: this pseudo random number generator was also mentioned in the 34C manual (or the standard applications manual). IIRC the source claimed it passed the spectral test by D. E. Knuth. Since on a 34C this generator required eleven steps just for the two constants (or two registers, equivalent to 14 steps), I used to generate random numbers in a much simpler way: r := frac(r+pi)2. I have absolutely no idea if and how well this method passes any mathematical test, but it used to work fine for my purposes - i.e. programming games like "Mastermind". ;-)
Dieter
Re: Looking for PRNG for HP-34C - Mike T. - 09-22-2012 Not very efficent but I used to use a vairation of the above on my HP33C and later my HP34C. I think it came from the HP97 manual but I can't be sure, hopefully I've remembered the seed correctly at that is an important bit!
001 LBL A It was a bit shorter on the HP33C as you didn't need to use labels which was just as well as there were only 49 program steps, so I usually entered the initial seed by hand before running the program.
Mike T. Edited: 22 Sept 2012, 7:11 p.m.
|