From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/68989 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:00:47 +0000 Message-ID: References: Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============2140245248==" X-Trace: dough.gmane.org 1307552530 15172 80.91.229.12 (8 Jun 2011 17:02:10 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 8 Jun 2011 17:02:10 +0000 (UTC) To: ConTeXt Original-X-From: ntg-context-bounces@ntg.nl Wed Jun 08 19:02:06 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 1QUM8p-0006An-25 for gctc-ntg-context-518@m.gmane.org; Wed, 08 Jun 2011 19:02:03 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 95DC5CADA1; Wed, 8 Jun 2011 19:02:02 +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 N6XmK32Lt0VJ; Wed, 8 Jun 2011 19:02:00 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 07CDDCAD93; Wed, 8 Jun 2011 19:02:00 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 6C104CAD93 for ; Wed, 8 Jun 2011 19:01:58 +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 xPm2QY211HOr for ; Wed, 8 Jun 2011 19:01:56 +0200 (CEST) Original-Received: from filter3-ams.mf.surf.net (filter3-ams.mf.surf.net [192.87.102.71]) by balder.ntg.nl (Postfix) with ESMTP id 210E5CAD8E for ; Wed, 8 Jun 2011 19:01:56 +0200 (CEST) Original-Received: from col0-omc2-s15.col0.hotmail.com (col0-omc2-s15.col0.hotmail.com [65.55.34.89]) by filter3-ams.mf.surf.net (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id p58H1sOQ018007 for ; Wed, 8 Jun 2011 19:01:55 +0200 Original-Received: from COL107-W7 ([65.55.34.72]) by col0-omc2-s15.col0.hotmail.com with Microsoft SMTPSVC(6.0.3790.4675); Wed, 8 Jun 2011 10:00:48 -0700 X-Originating-IP: [70.30.197.40] Importance: Normal In-Reply-To: X-OriginalArrivalTime: 08 Jun 2011 17:00:48.0014 (UTC) FILETIME=[9D2282E0:01CC25FD] X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=65.55.34.89; 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: 0cERt1Skk - 684e9791b16e - 20110608 X-Scanned-By: CanIt (www . roaringpenguin . com) on 192.87.102.71 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:68989 Archived-At: --===============2140245248== Content-Type: multipart/alternative; boundary="_d470cc4a-6f5e-4593-a322-963c714f95bf_" --_d470cc4a-6f5e-4593-a322-963c714f95bf_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable This following code works=2C except that the first random is always the sam= e (Analysis) for some reason. Anyone knows why ? \enableregime[il1]\starttext\startluacode userdata =3D userdata or {} math.= randomseed( os.time() ) function userdata.random(...) context(arg[math.ran= dom(1=2C #arg)]) end\stopluacode\def\CHOOSERANDOM#1{\ctxlua{userdata.random= (#1)}}\dorecurse{10}{\CHOOSERANDOM{"Maths"=2C "Physics"=2C "Algebra"=2C "An= alysis"=2C "Chemistry"=2C "Geometry"=2C "Wave equation"=2C "Schr=F6dinger e= quation"}\par}\stoptext Mathieu > From: otared@gmail.com > Date: Wed=2C 8 Jun 2011 18:52:36 +0200 > To: ntg-context@ntg.nl > Subject: [NTG-context] Random selection of a word in a set with lua and m= kiv >=20 > Hi all=2C >=20 > Assuming that we have a set of words or expressions=2C say > {Maths=2C Physics=2C Algebra=2C Analysis=2C Chemistry=2C Geometry=2C Wav= e equation=2C Schr=F6dinger equation} > is it possible to write a lua function=2C named for instance > randomselectword > which returns one of the words or expressions selected at random in the a= bove set? > Indeed this is intended to be used in a TeX file processed with mkiv. >=20 > Thanks in advance for any idea and help. >=20 > Best regards: OK > _________________________________________________________________________= __________ > If your question is of interest to others as well=2C please add an entry = to the Wiki! >=20 > maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-co= ntext > webpage : http://www.pragma-ade.nl / http://tex.aanhet.net > archive : http://foundry.supelec.fr/projects/contextrev/ > wiki : http://contextgarden.net > _________________________________________________________________________= __________ = --_d470cc4a-6f5e-4593-a322-963c714f95bf_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

This following code works=2C except that the first rand= om is always the same (Analysis) for some reason.

= Anyone knows why ?

\enableregime[il1]
\starttext
\startluacode
userdata =3D userdata or {}
math.rand= omseed( os.time() )
function userdata.random(...)
context(arg[math.random(= 1=2C #arg)])
end
\stopluacode
\def\CHOOSERANDOM#1{\ctxl= ua{userdata.random(#1)}}
\dorecurse{10}{\CHOOSERANDOM{"Maths"=2C = "Physics"=2C "Algebra"=2C "Analysis"=2C "Chemistry"=2C "Geometry"=2C "Wave = equation"=2C "Schr=F6dinger equation"}\par}
\stoptext
=


Mathieu




>=3B From: = otared@gmail.com
>=3B Date: Wed=2C 8 Jun 2011 18:52:36 +0200
>=3B= To: ntg-context@ntg.nl
>=3B Subject: [NTG-context] Random selection o= f a word in a set with lua and mkiv
>=3B
>=3B Hi all=2C
>= =3B
>=3B Assuming that we have a set of words or expressions=2C say>=3B {Maths=2C Physics=2C Algebra=2C Analysis=2C Chemistry=2C Geometry= =2C Wave equation=2C Schr=F6dinger equation}
>=3B is it possible to wr= ite a lua function=2C named for instance
>=3B randomselectword
>= =3B which returns one of the words or expressions selected at random in the= above set?
>=3B Indeed this is intended to be used in a TeX file proc= essed with mkiv.
>=3B
>=3B Thanks in advance for any idea and he= lp.
>=3B
>=3B Best regards: OK
>=3B _______________________= ____________________________________________________________
>=3B If y= our question is of interest to others as well=2C please add an entry to the= Wiki!
>=3B
>=3B maillist : ntg-context@ntg.nl / http://www.ntg.= nl/mailman/listinfo/ntg-context
>=3B webpage : http://www.pragma-ade.= nl / http://tex.aanhet.net
>=3B archive : http://foundry.supelec.fr/p= rojects/contextrev/
>=3B wiki : http://contextgarden.net
>=3B= __________________________________________________________________________= _________
= --_d470cc4a-6f5e-4593-a322-963c714f95bf_-- --===============2140245248== 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 ___________________________________________________________________________________ --===============2140245248==--