Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.postscript > #2535 > unrolled thread

on the predictability of srand

Started byPeter Billam <peter@www.pjb.com.au>
First post2016-04-22 05:48 +0000
Last post2016-05-18 01:42 -0700
Articles 2 — 2 participants

Back to article view | Back to comp.lang.postscript


Contents

  on the predictability of srand Peter Billam <peter@www.pjb.com.au> - 2016-04-22 05:48 +0000
    Re: on the predictability of srand luser- -droog <mijoryx@yahoo.com> - 2016-05-18 01:42 -0700

#2535 — on the predictability of srand

FromPeter Billam <peter@www.pjb.com.au>
Date2016-04-22 05:48 +0000
Subjecton the predictability of srand
Message-ID<slrnnhjepb.310.peter@box8.pjb.com.au>
Hi :-)  After srand is called with a particular argument, eg
  9999 srand
then AIUI rand will always generate the same sequence of integers
every time the page is viewed whether by gs or gv.  Does that
apply also to xpost ?   Is the rand algorithm in the PS spec ?

Peter

-- 

Peter Billam    www.pjb.com.au    www.pjb.com.au/comp/contact.html

[toc] | [next] | [standalone]


#2573

Fromluser- -droog <mijoryx@yahoo.com>
Date2016-05-18 01:42 -0700
Message-ID<c5adcedc-0745-4558-a488-b91fd4e14e55@googlegroups.com>
In reply to#2535
On Friday, April 22, 2016 at 12:48:29 AM UTC-5, Peter Billam wrote:
> Hi :-)  After srand is called with a particular argument, eg
>   9999 srand
> then AIUI rand will always generate the same sequence of integers
> every time the page is viewed whether by gs or gv.  Does that
> apply also to xpost ?   Is the rand algorithm in the PS spec ?
> 
> Peter

Oops. Missed this until now. The exact algorithm is
not specified just the interface of positive full-
range integers for all the int arguments.
And yes, the sequence should be repeatable given
the same seed. Deterministic Pseudo-Random-Number
Generator (PRNG).

To get non-predictable behavior, you need to seed
the prng with an entropy source. In most languages
you can use the time functions to get something 
usable. But IME gs never reports any time info
for the `usertime` operator.

So, for POSIX systems (including Cygwin) you can

  (/dev/rand)(r)file read pop srand

but of course that won't work without a /dev/rand
to read from. And it doesn't work with -DSAFER.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.postscript


csiph-web