0

The problem consist in using a random number on my prolog script, i have the next code on the prolog file script.pl:

main:-
    get_time(TS),
    set_random(TS),
    random(-1000.0, 1000.0, X),
    write('Random number: '),
    write(X),
    nl.

I execute the next command line on console:

swipl -s script.pl -g 'main' -t 'halt(1)'

And the output is:

% library(swi_hooks) compiled into pce_swi_hooks 0.00 sec, 2,224 bytes
% /home/script.pl compiled 0.01 sec, 704 bytes
Random number: -533.6139326519667

I can run the same command several times and i have the same output every time. I try work without change the random seed and the problem continues.

I'm working on Ubuntu 12.04 32 bits.

Help please!

tonylattke
  • 98
  • 7

2 Answers2

0

I've got an error running your code:

ERROR: set_random/1: Type error: `random_option' expected, found `1364628886.7626996'

i.e. set_random/1 argument is incorrect.

I tried to simplify, and it worked:

main:-
    random(-1000.0, 1000.0, X),
    write('Random number: '),
    write(X),
    nl.

yields different numbers on different calls

CapelliC
  • 59,646
  • 5
  • 47
  • 90
  • The problem is not run the script on prolog interpreter, the problem is runing the script on the command line with this instruction swipl -s script.pl -g 'main' -t 'halt(1)' because i need run this command on another program for generate several random number – tonylattke Mar 30 '13 at 15:24
  • No, i have the same number on every call. Random number: -533.6139326519667 – tonylattke Mar 30 '13 at 18:03
0

It is set_random(seed(888)) not set_random(TS)