Re: luamplib and randomseed
Dohyun Kim <[email protected]> Mon, 2 Aug 2021 20:44:51 +0900
| Newsgroups | gmane.comp.tex.metapost |
|---|---|
| Message-ID | <CAFzmAm2r_nX-Uia2BhNYBZgn9M=S3+9ja+F1PZ2pVk5kC1JHwA@mail.gmail.com> |
2021년 8월 2일 (월) 오전 7:56, Toby Thurston <[email protected]>님이 작성: > > 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` ? > Next version of luamplib will feed random integer values to the random_seed key of every new mplib instance. For the time being, you can do it by yourself by declaring as follows: randomseed := runscript"mp.print(math.random(4095))"; Best, -- Dohyun Kim Seoul, Republic of Korea -- http://tug.org/metapost/