Simple RND() Function
I came up with:
rol.l d0,d0 addq.l #x,d0
This gives pretty nice random numbers in 4 bytes. Use x=5 or x=7. The period of the number is of course dependant of the "seed" value. But with a constant adder the period is always not that long. You can also try adding changing numbers - for example a loopcounter.
Another method was shown to me by Graham:
divs.w #$4433,d0 swap d0
This is 6 bytes and takes much longer to execute - you also have to take care of the seed-number. It has to be 32 bit! But this one might produce random numbers with a longer period.
Well - both method do not deliver numbers , which are "random" enough for
serious usage (crypting etc). But they are ok for simple tasks, where length and speed is
more important, as textures, samples etc.
Last change: 16.01.2001