# Random algorithm

Jacques Hausser jacques.hausser at unil.ch
Sat Nov 15 05:40:57 CST 2008

```Interesting  demonstration ! If I'm not wrong, the probablity to get
twice the same sequence with the first method is about 6.25E-32 for
"really random" numbers (equiprobability for each number from 1 to
1000), what's a quite satisfying zero for dirty statisticians !

Jacques

Le 15 nov. 2008 à 09:55, Dave Cragg a écrit :

>
> On 13 Nov 2008, at 19:38, Richard Gaskin wrote:
>
>> So unless I'm missing something obvious (and it certainly wouldn't
>> be the first time), beginning with a fresh seed as Rev does and
>> then resetting it each time during the session seems a fair way to
>> avoid discernible reproducible patterns for most applications.
>
>
> Sorry for going back to this, but I'd just like to repeat my concern
> for resetting the seed using a "random" value.  I may have
> misunderstood what "resetting it each time" means. In some posts
> people have talked about resetting it before "each run" and others
> have talked about resetting before each call to the random function.
> My concern was with a particular "each run" situation.
>
> Say the task is to produce 5000 sets of 5 random numbers from 1 to
> 1000. (perhaps for a gaming task) The straightforward way to do this
> is to use the default Rev seed and call random(1000) 25000 times,
> dividing the results into 5000 sets of 5.
>
> An alternative would be to reset the randomSeed before generating
> each set of five numbers. At first glance, this might seem like a
> reasonable thing to do. But depending on how the seed is set, it
> could produce unwanted results. In the second script below, the seed
> is reset using the random of an incremented number. (4570422
> incremented by 1 to avoid getting stuck with the same seed)
>
> The two scripts  measure the number of repeated sequences that are
> generated by the two methods. The first method has yet to produce a
> repeated sequence here. But the second produces repeated sequences
> on almost every run. So by resetting the seed for "each run", the
> occurrence of a repeated sequence changes from a highly improbable
> event to a fairly safe bet.
>
>
> Cheers
> Dave
>
>
> METHOD 1 (no resetting)
> on mouseUp
>
>   repeat 5000
>      put empty into tVal
>      repeat 5
>         put random(1000) & "," after tVal
>      end repeat
>   end repeat
>
>   put 0 into tCount
>
>   repeat for each element tEl in tValArray
>      if tEl > 1 then
>      end if
>   end repeat
>   put tCount
> end mouseUp
>
> METHOD 2 (reset on every "set")
> on mouseUp
>   -----------------------
>   put 4570422 into tSeedBase
>   repeat 5000
>      put empty into tVal2
>      set the randomSeed to random(tSeedBase)
>      repeat 5
>         put random(1000) & "," after tVal2
>      end repeat
>   end repeat
>   ---------------------------
>
>   put 0 into tCount2
>
>   repeat for each element tEl in tValArray2
>      if tEl > 1 then
>      end if
>   end repeat
>
>   put tCount2
>
> end mouseUp
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution

******************************************
Prof. Jacques Hausser
Department of Ecology and Evolution
Biophore / Sorge
University of Lausanne
CH 1015 Lausanne