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.