From: Berk Birand
Subject: Pseudo-random number generator not random in first run
Date: 
Message-ID: <pan.2006.10.02.22.40.57.904615@yahoo.com>
Hi,

I am working on a project for my AI class that involves genetic
programming. It basically takes a specific list (of rules) and applies
random mutations until it reaches a final state. I wrote the whole
thing pretty quickly thanks to LISP, but a peculiar point caught my
attention.

When I first run clisp from the command-line using
$ clisp -i main.lsp

a function main (similar to C) is executed, and prints an integer (the
number of iterations it took the system to reach the goal state). Yet, the
first time the interpretor is executed, it always prints the same number!
But when I rerun (main) interactively, I get the diverse results one would
expect from a seemingly random process. I understand how these numbers are
not perfectly random, but is this much coincidence possible?

Can you explain me what is going on here?

Thanks,
Berk Birand

-- 
Posted via a free Usenet account from http://www.teranews.com

From: Pascal Bourguignon
Subject: Re: Pseudo-random number generator not random in first run
Date: 
Message-ID: <87r6xqmivq.fsf@thalassa.informatimago.com>
Berk Birand <········@yahoo.com> writes:

> Hi,
>
> I am working on a project for my AI class that involves genetic
> programming. It basically takes a specific list (of rules) and applies
> random mutations until it reaches a final state. I wrote the whole
> thing pretty quickly thanks to LISP, but a peculiar point caught my
> attention.
>
> When I first run clisp from the command-line using
> $ clisp -i main.lsp
>
> a function main (similar to C) is executed, and prints an integer (the
> number of iterations it took the system to reach the goal state). Yet, the
> first time the interpretor is executed, it always prints the same number!
> But when I rerun (main) interactively, I get the diverse results one would
> expect from a seemingly random process. I understand how these numbers are
> not perfectly random, but is this much coincidence possible?
>
> Can you explain me what is going on here?

Have you read  CLHS about random-states?

   make-random-state
   *random-state*


If you don't start with (make-random-state t), you can't expect different runs.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

"You cannot really appreciate Dilbert unless you read it in the
original Klingon"
From: Thomas A. Russ
Subject: Re: Pseudo-random number generator not random in first run
Date: 
Message-ID: <ymir6xm1g92.fsf@sevak.isi.edu>
Pascal Bourguignon <···@informatimago.com> writes:

> Berk Birand <········@yahoo.com> writes:
> 
> > Can you explain me what is going on here?
> 
> Have you read  CLHS about random-states?
> 
>    make-random-state
>    *random-state*
> 
> 
> If you don't start with (make-random-state t), you can't expect different runs.

And this is a deliberate design decision, since it makes you code much
easier to debug if you get the same "random" numbers each time!

I bet the corresponding second runs will end up being the same as well.

-- 
Thomas A. Russ,  USC/Information Sciences Institute