[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Random Number Question





On Mon, 5 May 2008, Bryan Parkoff wrote:

Hello folks,

   Do you know how random number work?  You use either Applesoft BASIC or
Integer BASIC.  You use the function like RND().  Take a look at my example
here.

10 PRINT INT( RND( 10 ) * 10)
20 GET A$
30 GOTO 10

   Apple II has chosen the random number of the range from 0 to 9 and print
each random number to the screen.  How do Apple II know to guess random
number?  Take a look at monitor routine $FD1B.  $4E and $4F are the high
byte of random and low byte of random.  It waits for the key to be pressed
while random number continues to increment.  If key is pressed, random
number stops to increment before it is printed to the screen.  Repeat the
procedure to increment random number while it waits for a key.
   Do you know the alternative implementation rather than keyin?  Do you
think to implement the clock to replace keyin?  The random number stops to
increment each one second while clock reads one second and another.  What do
you think?

If it's just counting until a keypress, that's your randomness.  One of
the odd things about random is that it is indeed random.  There's no
pattern to it. Just because you may get similar numbers in a row doesn't
mean it's not random.

One method often used is to sample some random source, like white noise.
The white noise is random, the sampling is clocked at a regular period.

That keyboard method, assuming I'm reading you right, is the reverse,
the source is a clock that's always counting, but when you press keys
is a fairly random thing and that gives the randomness.

The two methods are basically the same thing.

But since a white noise source isn't something you normally have on
hand, a lot of times equipment will have a pseudo-random output.  That's
done by clocking a shift register and having feedback at the right points.
But unlike the previous methods, it is merely pseudo-random.  Start it
up, and the output will always be the same as the last time it was
started.  Make the shift register long enough, and it will take a long
time before the pattern repeats, and thus it often is "random enough".


  Michael