Re: A83: Help (Random)


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

Re: A83: Help (Random)




First of all, deterministically speaking, there are NO random numbers. If I
asked you to give me a number, any number, then you are forced to come up with
a certain number, depending on what electrons are where in your brains. This
also means that computers cannot produce random numbers either. However
cryptic an algorithm you use to convert a seed number (f.ex. a timer) into a
pseudo-random number, there will always be a mathematical formula (that
probably can be simplified too).

What I am trying to say is that there's no use in writing complex
random-number-generating routines, as the numbers they generate wouldn't be
_really_ random anyway. Actually, adding 1 to the last "random" number is
often sufficient! But then the user would spot the algorithm too easy. I'd
recommend rotating the previous "random" number with some constant, and then
adding another constant. For an 8 bit number:

random:      ld   a,(prevrand)
             rla
             rla
             rla
             add  a,31h
             ld   (prevrand),a
             ret

Want a 16-bit number? Call the function twice!

Linus

On 17-May-98, Sumit wrote:

>I am trying to make a MAGIC 8-Ball on my TI-83 ASM, but I can't find
>any random number generator that doesn't use external BASIC variable. 
>If you know any random number generator from 1 to ##### then please
>send it to me as soon as possible.  I'd appreciate your reply.
>_________________________________________________________
>DO YOU YAHOO!?
>Get your free @yahoo.com address at http://mail.yahoo.com




Follow-Ups: References: