Setting random seed

Questions and problems about using polymake go here.

Moderator: Moderators

SimonKing
Posts: 14
Joined: 01 Mar 2017, 12:36

Setting random seed

Postby SimonKing » 03 Mar 2017, 19:05

Dear all,

I'd like to be able to set a random seed, so that subsequent calls to functions such as `rand_sphere` will have a predictable result.

I tried

Code: Select all

polytope > srand(5);
polytope > $P = rand_sphere(4, 23);
polytope > $V = $P->VERTICES;
polytope > @R = @$V[5];
polytope > print @R;
1 7794506731565509/9007199254740992 -3699097950061731/288230376151711744 479362551767877/2251799813685248 -8169534945610725/18014398509481984
polytope > srand(5);
polytope > $P = rand_sphere(4, 23);
polytope > $V = $P->VERTICES;
polytope > @R = @$V[5];
polytope > print @R;
1 -601059726080123/1125899906842624 -78635574677275/140737488355328 -675853917986593/1125899906842624 3712960453195519/18014398509481984


So, what to do instead, as `srand` doesn't seem to give the expected predictability?

Best regards,
Simon

User avatar
gawrilow
Main Author
Posts: 260
Joined: 25 Dec 2010, 17:40

Re: Setting random seed

Postby gawrilow » 03 Mar 2017, 20:12

> help 'rand_sphere';

functions/Producing a polytope from scratch/rand_sphere:
rand_sphere(d, n; Options) -> Polytope

Produce a d-dimensional polytope with n random vertices
uniformly distributed on the unit sphere.

Arguments:
Int d the dimension
Int n the number of random vertices

Options:
seed => Int controls the outcome of the random number generator;
fixing a seed number guarantees the same outcome.
precision => Int Number of bits for MPFR sphere approximation

SimonKing
Posts: 14
Joined: 01 Mar 2017, 12:36

Re: Setting random seed

Postby SimonKing » 03 Mar 2017, 22:09

gawrilow wrote:> help 'rand_sphere';
...


I am afraid that doesn't answer my question. I know that I can supply a random seed to certain functions. What I wonder: Is there a way to bring Polymake into a state such that the same sequence of commands starting from that state will always have the same result, of course without being forced to supply additional arguments to the functions in the sequence? `rand_sphere` has only been an example.

User avatar
gawrilow
Main Author
Posts: 260
Joined: 25 Dec 2010, 17:40

Re: Setting random seed

Postby gawrilow » 03 Mar 2017, 22:19

SimonKing wrote:... Is there a way to bring Polymake into a state such that the same sequence of commands starting from that state will always have the same result, of course without being forced to supply additional arguments to the functions in the sequence?


No, it's not possible on purpose. Every function producing random results fetches an individual seed value from /dev/urandom, unless an explicit value is provided as an optional argument. The latter is primarily used in the testsuite. Having unpredictable results is deemed a desired behavior and therefore done so by default.


Return to “Helpdesk”

Who is online

Users browsing this forum: No registered users and 1 guest

cron