From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/68991 Path: news.gmane.org!not-for-mail From: Mathieu Dupont Newsgroups: gmane.comp.tex.context Subject: Re: Random selection of a word in a set with lua and mkiv Date: Wed, 8 Jun 2011 17:19:15 +0000 Message-ID: References: , <4DEFAC66.9000002@wxs.nl> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1442362694==" X-Trace: dough.gmane.org 1307553582 22151 80.91.229.12 (8 Jun 2011 17:19:42 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 8 Jun 2011 17:19:42 +0000 (UTC) To: Hans Hagen , ConTeXt Original-X-From: ntg-context-bounces@ntg.nl Wed Jun 08 19:19:38 2011 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([195.12.62.10]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QUMPn-0006M6-3L for gctc-ntg-context-518@m.gmane.org; Wed, 08 Jun 2011 19:19:35 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 730DECAD9E; Wed, 8 Jun 2011 19:19:34 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id qshlkrII2faK; Wed, 8 Jun 2011 19:19:31 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 9B4A1CAD8E; Wed, 8 Jun 2011 19:19:31 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id B20CCCAD8E for ; Wed, 8 Jun 2011 19:19:29 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id gunT+mGLF7Vm for ; Wed, 8 Jun 2011 19:19:18 +0200 (CEST) Original-Received: from filter4-til.mf.surf.net (filter4-til.mf.surf.net [194.171.167.220]) by balder.ntg.nl (Postfix) with ESMTP id D32B9CAD8C for ; Wed, 8 Jun 2011 19:19:18 +0200 (CEST) Original-Received: from col0-omc2-s9.col0.hotmail.com (col0-omc2-s9.col0.hotmail.com [65.55.34.83]) by filter4-til.mf.surf.net (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id p58HJHn9021281 for ; Wed, 8 Jun 2011 19:19:17 +0200 Original-Received: from COL107-W35 ([65.55.34.73]) by col0-omc2-s9.col0.hotmail.com with Microsoft SMTPSVC(6.0.3790.4675); Wed, 8 Jun 2011 10:19:16 -0700 X-Originating-IP: [70.30.197.40] Importance: Normal In-Reply-To: <4DEFAC66.9000002@wxs.nl> X-OriginalArrivalTime: 08 Jun 2011 17:19:16.0300 (UTC) FILETIME=[31B988C0:01CC2600] X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=65.55.34.83; country=US; region=WA; city=Redmond; postalcode=98052; latitude=47.6801; longitude=-122.1206; metrocode=819; areacode=425; http://maps.google.com/maps?q=47.6801,-122.1206&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 05ERtjh1r - f94e4d2928c5 - 20110608 X-Scanned-By: CanIt (www . roaringpenguin . com) on 194.171.167.216 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.12 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:68991 Archived-At: --===============1442362694== Content-Type: multipart/alternative; boundary="_44b31f14-1735-4a79-b626-8e057a789ddd_" --_44b31f14-1735-4a79-b626-8e057a789ddd_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I see.So it can be fixed by simply adding the first line before the second = :\CHOOSERANDOM{""}\CHOOSERANDOM{"Maths"=2C "Physics"=2C "Algebra"=2C "Analy= sis"=2C "Chemistry"=2C "Geometry"=2C "Wave equation"=2C "Schr=F6dinger equa= tion"}Thanks=2C that fixes one of my problems ! Mathieu > Date: Wed=2C 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 a= nd mkiv >=20 > On 8-6-2011 7:00=2C Mathieu Dupont wrote: > > > > > > This following code works=2C except that the first random is always the= same (Analysis) for some reason. > > Anyone knows why ? > > \enableregime[il1]\starttext\startluacode userdata =3D userdata or {} m= ath.randomseed( os.time() ) function userdata.random(...) context(arg[math= .random(1=2C #arg)]) end\stopluacode\def\CHOOSERANDOM#1{\ctxlua{userdata.ra= ndom(#1)}}\dorecurse{10}{\CHOOSERANDOM{"Maths"=2C "Physics"=2C "Algebra"=2C= "Analysis"=2C "Chemistry"=2C "Geometry"=2C "Wave equation"=2C "Schr=F6ding= er equation"}\par}\stoptext >=20 > Because context remembers the seed (is reported in the log). Delete the=20 > tuc file and you will get another value. We could get oscillation=20 > otherwise. >=20 >=20 > ----------------------------------------------------------------- > 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 > ----------------------------------------------------------------- = --_44b31f14-1735-4a79-b626-8e057a789ddd_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

I se= e.

=
So it can be fixed by simply add= ing the first line before the second :

\CHOOSERANDOM{""}
\CHOO= SERANDOM{"Maths"=2C "Physics"=2C "Algebra"=2C "Analysis"=2C "Chemistry"=2C = "Geometry"=2C "Wave equation"=2C "Schr=F6dinger equation"}

Thanks=2C that fixes one of my problems !



Mathieu




>=3B Date: Wed=2C 8 Jun 2011 19:07:50 += 0200
>=3B From: pragma@wxs.nl
>=3B To: ntg-context@ntg.nl
>= =3B CC: mathieudupont@hotmail.com
>=3B Subject: Re: [NTG-context] Rand= om selection of a word in a set with lua and mkiv
>=3B
>=3B On 8= -6-2011 7:00=2C Mathieu Dupont wrote:
>=3B >=3B
>=3B >=3B
= >=3B >=3B This following code works=2C except that the first random is = always the same (Analysis) for some reason.
>=3B >=3B Anyone knows w= hy ?
>=3B >=3B \enableregime[il1]\starttext\startluacode userdata = =3D userdata or {} math.randomseed( os.time() ) function userdata.random(..= .) context(arg[math.random(1=2C #arg)]) end\stopluacode\def\CHOOSERANDOM#1= {\ctxlua{userdata.random(#1)}}\dorecurse{10}{\CHOOSERANDOM{"Maths"=2C "Phys= ics"=2C "Algebra"=2C "Analysis"=2C "Chemistry"=2C "Geometry"=2C "Wave equat= ion"=2C "Schr=F6dinger equation"}\par}\stoptext
>=3B
>=3B Becaus= e context remembers the seed (is reported in the log). Delete the
>= =3B tuc file and you will get another value. We could get oscillation
&= gt=3B otherwise.
>=3B
>=3B
>=3B --------------------------= ---------------------------------------
>=3B = Hans Hagen | PRAGMA ADE
>=3B Ridderst= raat 27 | 8061 GH Hasselt | The Netherlands
>=3B tel: 038 477 53 = 69 | voip: 087 875 68 74 | www.pragma-ade.com
>=3B = | www.pragma-pod.nl
>=3B ------------------= -----------------------------------------------
= --_44b31f14-1735-4a79-b626-8e057a789ddd_-- --===============1442362694== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ___________________________________________________________________________________ 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://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________ --===============1442362694==--