METAPOST's uniformdeviate is not truly random (seed)
![](https://secure.gravatar.com/avatar/c83fb4134167a11422c23048fb8a85e3.jpg?s=120&d=mm&r=g)
I’m trying to get a real random number in METAPOST MWE: \startMPpage[instance=doublefun] show uniformdeviate 60; \stopMPpage Every time I run this, it shows the same result. I tried playing around with the randomseed, but for instance when I do two runs shortly after each other they still are very predictable. E.g. this in METAPOST: whatever = lua( "math.randomseed( tonumber(tostring(os.time()):reverse():sub(1,6)) )"); randomseed := lua.math.random(); minutespast := uniformdeviate 60; Called shortly after each other (two LMTX runs) gets me the same result. What is a good way to get better random numbers in METAPOST (LMTX)? Thanks, G
![](https://secure.gravatar.com/avatar/74d41c3215dcdd377343cdc47311757c.jpg?s=120&d=mm&r=g)
Gerben Wierda schrieb am 23.06.2020 um 17:57:
I’m trying to get a real random number in METAPOST
MWE:
\startMPpage[instance=doublefun] show uniformdeviate 60; \stopMPpage
Every time I run this, it shows the same result. I tried playing around with the randomseed, but for instance when I do two runs shortly after each other they still are very predictable. E.g. this in METAPOST:
whatever = lua( "math.randomseed( tonumber(tostring(os.time()):reverse():sub(1,6)) )"); randomseed := lua.math.random(); minutespast := uniformdeviate 60;
Called shortly after each other (two LMTX runs) gets me the same result.
This is on purpose because ConTeXt needs multiple runs to create the index, toc etc. and fixed values are used to avoid changes in the layout between these runs.
What is a good way to get better random numbers in METAPOST (LMTX)? When you delete the tuc-file you get a different number.
context --purgeall <file> Wolfgang
participants (2)
-
Gerben Wierda
-
Wolfgang Schuster