YAP Prolog random lack of randomness

When executing the next Prolog program with YAP, the output is always the same, namely the integer 233.

:- use_module(library(random)).    
x:- random(1,1000,X), writeln(X).

For example, if I execute the following bash script, the output will always be the same integer (233).

for k in `seq 0`
do
  yap -l test.pl << %
  x.
%
done

If I repeat this procedure using swipl, then each time each result will be different, i.e. random.

Can anyone explain this?

+4
source share
2 answers

usually random generators require something like calling set_seed (SomeReallyRandomValue), C often uses a seed (time (0)). So I think

datime(datime(_Year, _Month, _DayOfTheMonth, _Hour, Minute, Second)),
X is Minute * Second,Y=X,Z=X,
setrand(rand(X,Y,Z)),

can work

+2
source

First of all, the first!

( ) , .

PRNG , (a.k.a. "seed" ) ​​ ( ).

: (, , ,...) PRNG . , .

+4

Source: https://habr.com/ru/post/1610816/


All Articles