Looking for PRNG for HP-34C



#5

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.


#6

I remember using xn+1 = FRC ( 9821 xn + 0.211327 ) on all of my 41C*
See for yourself if these can fit your goal.
Greetings,
Massimo


Edited: 22 Sept 2012, 5:55 a.m.


#7

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


#8

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
002 .
003 5
004 2
005 8
006 4
007 1
008 6
009 3
010 LBL 0
011 f PSE
012 9
013 9
014 7
015 x
016 g FRAC
017 GTO 0

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.


Possibly Related Threads…
Thread Author Replies Views Last Post
  HP-34C Draining battery quickly Bill Crowell 2 1,412 09-08-2013, 08:30 AM
Last Post: aj04062
  HP-34C Curiosity Matt Agajanian 7 2,761 08-23-2013, 06:02 PM
Last Post: Stephan Matthys
  HP-34C Emulator BShoring 8 2,771 03-30-2013, 05:04 PM
Last Post: BShoring
  HP-34C Storage Register Arithmetic & Programming Matt Agajanian 14 4,277 05-08-2012, 11:04 AM
Last Post: Matt Agajanian
  A longstanding HP-34C mystery Matt Agajanian 11 3,497 05-03-2012, 02:29 AM
Last Post: Alexander Oestert
  HP 34C display problem james summers 11 3,992 04-05-2012, 06:07 PM
Last Post: james summers
  HP 34C and 67 for Android Vincent Weber 16 4,651 01-24-2012, 11:38 AM
Last Post: Alexander Oestert
  34C display problem Daniel CLEMENT 8 2,535 07-11-2011, 09:45 PM
Last Post: Michael de Estrada
  HP-34C Excitement Mark Henderson 9 2,525 05-21-2010, 04:33 PM
Last Post: Vieira, Luiz C. (Brazil)
  HP 34C - which way round are the batterys fitted? Jon Duke 6 2,206 03-30-2010, 11:39 AM
Last Post: Michael de Estrada

Forum Jump: