I see.So it can be fixed by simply adding the first line before the second :\CHOOSERANDOM{""}\CHOOSERANDOM{"Maths", "Physics", "Algebra", "Analysis", "Chemistry", "Geometry", "Wave equation", "Schrödinger equation"}Thanks, that fixes one of my problems ! Mathieu
Date: Wed, 8 Jun 2011 19:07:50 +0200 From: pragma@wxs.nl To: ntg-context@ntg.nl CC: mathieudupont@hotmail.com Subject: Re: [NTG-context] Random selection of a word in a set with lua and mkiv
On 8-6-2011 7:00, Mathieu Dupont wrote:
This following code works, except that the first random is always the same (Analysis) for some reason. Anyone knows why ? \enableregime[il1]\starttext\startluacode userdata = userdata or {} math.randomseed( os.time() ) function userdata.random(...) context(arg[math.random(1, #arg)]) end\stopluacode\def\CHOOSERANDOM#1{\ctxlua{userdata.random(#1)}}\dorecurse{10}{\CHOOSERANDOM{"Maths", "Physics", "Algebra", "Analysis", "Chemistry", "Geometry", "Wave equation", "Schrödinger equation"}\par}\stoptext
Because context remembers the seed (is reported in the log). Delete the tuc file and you will get another value. We could get oscillation otherwise.
----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------