Personal Computer News


HX20 Random Number Seed

 
Published in Personal Computer News #053

HX20 Random Number Seed

The following routine for the HX20 can be used to produce a random number seed at the start of a Basic program. The routine uses the internal timer, locations &H0009 and &H000A, to provide an integer in the range -32768 to +32767. The timer counts from 0 to &HFFFF and then resets to zero again. This process takes 107 milliseconds and so there are approximately nine complete count cycles per second.

   10 POKE &H7E,(&H80 OR PEEK(&H7E))
   20 RANDOMISE 256*PEEK(&H9)+PEEK(&HA)-32768
   30 POKE&H7E,(&H7F AND PEEK(&H7E))
   40 REMAINDER OF PROGRAM FOLLOWS

J. M. Wald, Bitterne Park, Southampton

J. M. Wald