[TIB] Re: randseed on TI-89


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

[TIB] Re: randseed on TI-89




> 
> Think of the seed as an index into a table of pseudo random numbers.
> The table is static, that is seeding with the same value will always
> return the same sequence of random numbers.  The conventional way to
> seed a random number generator is to use the current time from an
> internal clock as the seed, unfortunately the 89/92+ doesn't have a
> real time clock...
> 
> This seems to leave us with no method to seed the random number
> generator in a non-deterministic way, since after a reset any
> algorythm used will produce the same seed value.
> 

<SNIP>

Actually, it is possible.
You would normally use the clock, to seed a pseudo random generator
with a truly random number, resulting in a real random generator.
Indeed, ti calcs don't have clocks, and (reset) algorithms return
the same value. So, we'll have to use a trick:

(This is 83-basic, I hope you understand it)

:ClrHome
:Disp "","NAME","VERSION"           ;   intro screen
:Repeat getKey                      ;   loop untill a key is pressed
   :R+rand->R                       ;   change R
:End
:R->rand                            ;   seed the pseudo random generator
                                    ; with a really random number making
                                    ; it a real random generator
; rest of program

Note:
Don't use "0->R" in front of the loop, that makes it "less random"
Don't use "R+1->R", that too, makes it "less random"

This isn't perfect, but it does come close.

Rob van Wijk
<robvanwijk@gmx.net>

-- 
Sent through GMX FreeMail - http://www.gmx.net




References: