Problem with random/1: seed always the same?

View: New views
2 Messages — Rating Filter:   Alert me  

Problem with random/1: seed always the same?

by Ivo Swartjes :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I have a problem with random/1. The documentation states that "the seed
of this random generator is determined by the system clock when
SWI-Prolog was started". However, whenever I start and restart
SWI-Prolog, and ask random(X), I always get the same random sequence
(starting with 0.233193). My suspicion is that either the seed isn't
set, or it isn't used by random/1.

I use SWI-Prolog 5.6.54 and run it on Windows XP. A colleague uses
SWI-Prolog 5.6.50 on XP and gets exactly the same random sequence.

Any ideas why this is?

Thanks,
Ivo Swartjes

------------
For further info, please visit http://www.swi-prolog.org/

To unsubscribe, send a plaintext mail with "unsubscribe prolog <e-mail>"
in its body to majordomo@...

Re: Problem with random/1: seed always the same?

by Jan Wielemaker :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thursday 15 May 2008 18:00:15 Ivo Swartjes wrote:

> Hi,
>
> I have a problem with random/1. The documentation states that "the seed
> of this random generator is determined by the system clock when
> SWI-Prolog was started". However, whenever I start and restart
> SWI-Prolog, and ask random(X), I always get the same random sequence
> (starting with 0.233193). My suspicion is that either the seed isn't
> set, or it isn't used by random/1.
>
> I use SWI-Prolog 5.6.54 and run it on Windows XP. A colleague uses
> SWI-Prolog 5.6.50 on XP and gets exactly the same random sequence.
>
> Any ideas why this is?

Mixup of function and predicate. The function random/1 is built-in and
used as A is random(Max); the predicate random/1 is provided by
library(random) and part of the clib package. This version must be
explicitely seeded.

        --- Jan



------------
For further info, please visit http://www.swi-prolog.org/

To unsubscribe, send a plaintext mail with "unsubscribe prolog <e-mail>"
in its body to majordomo@...
LightInTheBox - Buy quality products at wholesale price