bug-ghostscript
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature request: Pre-seeding the random number generator


From: Sean M. Burke
Subject: feature request: Pre-seeding the random number generator
Date: Sat, 21 Oct 2006 14:56:32 -0800
User-agent: Thunderbird 1.5.0.7 (X11/20060922)

This is a feature request: I'd really really appreciate if you could
make the random number generator in ghostscript pre-seeded.

(Perl has been doing this for about ten years-- in the surprisingly
rare circumstances where programmers want /predictable/
pseudorandomness, they just need to explicitly feed srand an particular value.
If you want a bit of inspiration from Perl's pre-seeding, the code for
it is in here:
 http://www.devdaily.com/scw/c/perl-5.8.5/util.c.shtml
and look for the function "Perl_seed(pTHX)".)

I considered just replacing rand with something that reads from /dev/random, but besides portability problems, such file operations are apparently inaccessible in gs's (imminently default) SAFER mode.

I used to pre-seed by just doing "realtime srand", but now I see that
realtime has a very NONrandom value (see below).

I know that PostScript docs typically warn that rand's generator is typically pretty dumb, but that doesn't mean it /has/ to be dumb in GhostScript.


% perl -e 'system q[echo realtime dup srand rand exch stack |gs -q -]
for(1..20)'
81
1361367
81
1361367
82
1378174
85
1428595
82
1378174
81
1361367
84
1411788
83
1394981
83
1394981
81
1361367
81
1361367
81
1361367
80
1344560
83
1394981
81
1361367
83
1394981
80
1344560
81
1361367
83
1394981
87
1462209







reply via email to

[Prev in Thread] Current Thread [Next in Thread]