Randomize Timer?
Author Message
Randomize Timer?

To whoever cares,
I am trying to make a small game.  In this game, you have to look at a
frequency drawing of an alien race and then see if a randomly picked
drawing looks similar.  Would I use the Randomize timer for this?  And
if so, how?

-Chase

P.S. Please quit picking on my name, Im just quoting Wile E Coyote, -k-?

Thu, 06 Jan 2000 03:00:00 GMT
Randomize Timer?

Quote:
>I am trying to make a small game.  In this game, you have to look at a
>frequency drawing of an alien race and then see if a randomly picked
>drawing looks similar.  Would I use the Randomize timer for this?  And
>if so, how?

If you don't have a RANDOMIZE statement early in your program, all calls
to the RND() function will return the same number.  The RANDOMIZE
statement takes an argument, usually called the "seed", that initializes
the (pseudo-) random number generator.  The handiest source for a random
seed is the value of the TIMER function, which returns the number of timer
ticks (about 18.2 / second) since midnight.

Have you looked up RND() and RANDOMIZE in the QB online help?

Thu, 06 Jan 2000 03:00:00 GMT
Randomize Timer?

Thanks  Steve Rush!

Quote:

> If you don't have a RANDOMIZE statement early in your program, all calls
> to the RND() function will return the same number.  The RANDOMIZE
> statement takes an argument, usually called the "seed", that initializes
> the (pseudo-) random number generator.

THANX I needed that little bit!

The handiest source for a random

Quote:
> seed is the value of the TIMER function, which returns the number of timer
> ticks (about 18.2 / second) since midnight.

Uhhh I dont know if I like that too much for this game...

Quote:
> Have you looked up RND() and RANDOMIZE in the QB online help?

Me and help DON't get along, anyways most of those try to teach SO much,
they don't even do a good job at teaching the littlest things!
Personilized text I find is much better, but yes I have browsed some
help files.....

-Chase

Sat, 08 Jan 2000 03:00:00 GMT
Randomize Timer?

Quote:
>I am trying to make a small game.  In this game, you have to look at a
>frequency drawing of an alien race and then see if a randomly picked
>drawing looks similar.  Would I use the Randomize timer for this?  And
>if so, how?

It is a good idea to use RANDOMIZE TIMER to ensure that the random
number generator is seeded with a new value each time the program is
run.

See, computers can't really generate random numbers, they generate a
pseudo-random sequence of numbers.  The algorithm that does this needs
a "seed" value to start the sequence of "random" numbers.  Given the
same seed value, the sequence of "random" numbers will be the same.
To see this, try this code:

FOR i% = 1 TO 10
PRINT ((10 - 1 + 1) * RND + 1)        ' generate a random number
' between 1 and 10
NEXT i%

Every time you run it, you will get the same sequence of "random"
numbers.  The numbers will look random, compared to each other, but
they will be exactly the same for each run.

Now, run this code:

RANDOMIZE TIMER    ' seed the RDN function with the time of day

FOR i% = 1 TO 10
PRINT ((10 - 1 + 1) * RND + 1)
NEXT i%

Each time you run this code you will get a different sequence of
"random" numbers.  The RANDOMIZE TIMER function takes the time of day
(TIMER) as the seed for the random number generator, ensuring that it
produces a different sequence each time.

Actually, if the software is run at the exact same time each day, it
will still produce the same sequence.  I suppose one could futz with
the result of the TIMER command (maybe multiply or divide it by the
Julian day of the year?).  But given the resolution of the TIMER
function, this shouldn't really be necessary.

Sun, 09 Jan 2000 03:00:00 GMT

 Page 1 of 1 [ 4 post ]

Relevant Pages