From: Reinier Zwitserloot
Subject: Re: Randomize Timer
Get the number off 0x0040:0x006C (DOS INCs this 18.2 times a sec. If you
dig through the INT 9 ISR you'll find it somewhere). that's a memory
address, by the way. and INT 9 ISR is an interrupt that gets triggered
18.2 times a second. the Powerbasic POPUP TIMER uses it, for one.
(That's oversimplifying it.. INT 9 calls INT 1C which you should use)
take this number as seed value. (That's what RANDOMIZE TIMER will do.)
then when you need a random number shift this some way some amount of
bits (doesn't matter what you do) and add a constant (doesn't matter
what constant) and store that into the seed value variable. That'll get
you a list of pretty good pseudo-randomness. For real randomness you'll
have to write a routine that asks the user to be creative and mash away
at the keyboard. PSP does this to generate random numbers for it's key
generation process. (Ask you to mash away at the keyboard and/or move
your mouse a little left and right). Alternatively you can watch random
channels in the background for a bit. all those last procedures are much
more complicated and you really need it. ie: if you need random numbers
for a game or demo (not a program demo, a piece of art on a computer,
basically) then the seed thing works. If you need asm code drop me a
mail. PB's code works similar except that it always generates between 0
and 1 whereas the procedure above will generate integers between 0 and
65535.
Paulo Jorge de O. C. Matos (PDestroy) wrote:
>
> Hi,
> I have read that when for example we make randomize timer and then
alculate
> a random nunbver using RND the computer uses a formula to calculate it
sing
> the seconds of the inner clock. Anyonw knows what's the formula or how the
> computer gets the number?
>
> Regards,
> Paulo Jorge Matos
--
- Ray Zwitserloot.
R.Zwitserloot@antispam.BTInternet.com
Change the E-mail address to reply!
----------------------------------------------------
*** QwkNews (tm) v2.1
* [TN71] alt.lang.powerbasic POWER_BAS Gateway
--- GEcho 1.20/Pro
---------------
* Origin: Toast House Remote (1:100/560.2)
|