ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* METAPOST's uniformdeviate is not truly random (seed)
@ 2020-06-23 15:57 Gerben Wierda
  2020-06-23 16:14 ` Wolfgang Schuster
  0 siblings, 1 reply; 2+ messages in thread
From: Gerben Wierda @ 2020-06-23 15:57 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: METAPOST's uniformdeviate is not truly random (seed)
  2020-06-23 15:57 METAPOST's uniformdeviate is not truly random (seed) Gerben Wierda
@ 2020-06-23 16:14 ` Wolfgang Schuster
  0 siblings, 0 replies; 2+ messages in thread
From: Wolfgang Schuster @ 2020-06-23 16:14 UTC (permalink / raw)
  To: mailing list for ConTeXt users

     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

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-23 16:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-23 15:57 METAPOST's uniformdeviate is not truly random (seed) Gerben Wierda
2020-06-23 16:14 ` Wolfgang Schuster

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).