[futurebasic] Re: RANDOM QUESTION

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : December 1997 : Group Archive : Group : All Groups

From: Jason Conkey <jconkey@...>
Date: Sun, 21 Dec 1997 13:17:50 -0800
Rick, after reading your post, I thought, if the RANDOMIZE statement is
being used inside a loop that could explain the problem:

FOR a=1 to 20
  PRINT RND(100)

If RANDOMIZE was called more than once per tick, and RND is also called
then the numbers would be the same within the same tick.  The RANDOMIZE
statement resets the "random" sequence each time it is called, so if you
use it a fast loop, you will reset to the beginning of the same sequence
over and over, thus RND will give the same number each time, until the tick
value changes.

Arcnon, I know I did not write this very clearly, but hopefully it makes
sense.  The cure for the problem is to take the RANDOMIZE statement out of
the loop.

>Arcnon wrote:
>> I have a old version of future basic so you may have to look in
>> retrospect to answer my question.
>> I am try to generate a random number inside a function and it appears
>> that the random statement doesn't "reset" the seed on a loop inside the
>> fn.  Does anyone know off hand what I am doing wrong.
>I am using version 2.1.3, and the RANDOMIZE statement seems to reset the
>seed in my experiments.
>How are you using RANDOMIZE?  If you want RND to regenerate the same
>sequence of random numbers each time, you need to explicitly provide a
>particular seed value before each sequence of RND calls, like this:
>  FOR i = 1 to 20
>    PRINT RND(100)
>The above will generate the same sequence of 20 random numbers each time
>you run it.
>If you use RANDOMIZE _without_ a seed expression, then it will _not_
>reset the seed to what you want (more accurately, it will use the value
>of FN TICKCOUNT as the "seed," which is almost certain to be _different_
>each time it's called).  You need to provide the _same_ seed value each
>time, if you want to re-generate the same sequence of random numbers.
>- Rick
>To unsubscribe, send ANY message to <futurebasic-unsubscribe@...>