[metapost] luamplib and randomseed

Toby Thurston thurston at eml.cc
Mon Aug 2 00:56:03 CEST 2021


There appear to be a couple of small problems with the implementation of `randomseed` in luamplib.

First one is that the default value appears only to change every minute.

If I run this program through `mpost`

  prologues:=3;outputtemplate:="rs.eps";
  beginfig(1);
  label.top(decimal normaldeviate, origin);
  label.bot(decimal minute, origin);
  endfig;
  end

Then I get a different value for the random number every time, and the minute
value changes every minute (as expected).

But if I run the same program through lualatex — LuaHBTeX, 1.13.0 (TL 2021)

  \documentclass{standalone} \usepackage{luamplib} \begin{document} \begin{mplibcode}
  beginfig(1);
  label.top(decimal normaldeviate, origin);
  label.bot(decimal minute, origin);
  endfig;
  \end{mplibcode} \end{document}

then the random number only changes when the minute changes....

Apparently the luamplib version is using the old default randomseed of day + minute of day despite 
the fact that the relevant bit of mp.w says this:

    The global variable |random_seed| was introduced in version 0.9,
    for the sole reason of stressing the fact that the initial value of the
    random seed is system-dependant. The initialization code below will initialize
    this variable to |(internal[mp_time] div unity)+internal[mp_day]|, but this
    is not good enough on modern fast machines that are capable of running
    multiple MetaPost processes within the same second.
 
Could we have the default seed to set to something that is "good enough"?  Or at least something
that is consistent with `mpost` ?


Secondly, if I include this in an mpost program 

   randomseed := uniformdeviate infinity;

I get this useful output in the log file

   {randomseed:=3768.2096} 

showing me the randomseed value actually used (which I might want to re-use later...)

But with lualatex nothing gets written to the log when I call randomseed.
Could this be made consistent with `mpost` as well please?  

thanks and best wishes, Toby Thurston
   




More information about the metapost mailing list.