[metapost] a "randomseed" workaround
Larry Siebenmann
laurent at math.toronto.edu
Sun Mar 6 05:57:29 CET 2005
Hello all,
Since, in many mp implementations, the automatic
"uniformdeviate" and "normaldeviate" seeding mechanism of
mp is not sufficiently responsive to the passage of time,
I offer the following simple workaround -- that usefully
softens Taco's verdict (Mon, 28 Feb 2005):
> Setting seeds is system-dependant (because all portable
> solutions depend on the current time)
It took me quite a while to locate the conversion
from string to numeric by "scantokens" (see below).
Nothing about it in mp documentation; its not a syntax one
easily infers from other languages. It would be helpful
to add to mp documentation a fairly complete table of
primitives that are common to mf and mp.
I've updated "ProfileBezier.mp" at
http://topo.math.u-psud.fr/~lcs/mp/ProfileBezier/
since it benefits noticeably.
It took me quite a while to locate the conversion
from string to numeric by "scantokens" (see below).
Nothing about it in mp documentation; its not a syntax one
easily infers from other languages. It would be helpful
to add to mp documentation a fairly complete table of
primitives that are common to mf and mp. Seems only
the differences are systematically listed.
Cheers
Laurent S.
%%% Patch for a mp file that uses
%%% uniformdeviate or normaldeviate
%%% and can be expected to run more often than
%%% "randomseed" is updated.
%%% Belongs in header.
string str;
numeric seed_adjuvant;
%
str:=readfrom "SeedBank";
%show str;
if str = EOF:
write "1" to "SeedBank";
write EOF to "SeedBank";
seed_adjuvant:=0
else:
seed_adjuvant:= scantokens(str);
seed_adjuvant:= (seed_adjuvant+1) mod 3600;
write (decimal seed_adjuvant) to "SeedBank";
write EOF to "SeedBank";
fi;
%
randomseed:= day + (time + seed_adjuvant)*epsilon;
%
%% Default for metafont is (in effect)
%% randomseed:= day + time*epsilon
%%% End of patch.
More information about the metapost
mailing list