From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/68997 Path: news.gmane.org!not-for-mail From: Otared Kavian Newsgroups: gmane.comp.tex.context Subject: Re: Random selection of a word in a set with lua and mkiv Date: Wed, 8 Jun 2011 22:12:07 +0200 Message-ID: <0B74BB58-30A1-4B93-9240-38CACB725BCF@gmail.com> References: Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: multipart/mixed; boundary="===============2105790765==" X-Trace: dough.gmane.org 1307563949 23697 80.91.229.12 (8 Jun 2011 20:12:29 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 8 Jun 2011 20:12:29 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Wed Jun 08 22:12:22 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 1QUP6y-0005uy-4g for gctc-ntg-context-518@m.gmane.org; Wed, 08 Jun 2011 22:12:20 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id DFD1ECADA6; Wed, 8 Jun 2011 22:12:18 +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 LwEDte8cVVT1; Wed, 8 Jun 2011 22:12:16 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id D6D97CAD99; Wed, 8 Jun 2011 22:12:15 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 727E3CAD99 for ; Wed, 8 Jun 2011 22:12:14 +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 KYwDQl0XJD7K for ; Wed, 8 Jun 2011 22:12:12 +0200 (CEST) Original-Received: from filter5-til.mf.surf.net (filter5-til.mf.surf.net [194.171.167.221]) by balder.ntg.nl (Postfix) with ESMTP id 0963FCAD8B for ; Wed, 8 Jun 2011 22:12:12 +0200 (CEST) Original-Received: from mail-ww0-f41.google.com (mail-ww0-f41.google.com [74.125.82.41]) by filter5-til.mf.surf.net (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id p58KCAfQ023020 for ; Wed, 8 Jun 2011 22:12:11 +0200 Original-Received: by wwi18 with SMTP id 18so3691564wwi.2 for ; Wed, 08 Jun 2011 13:12:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:mime-version:content-type:subject:date :in-reply-to:to:references:message-id:x-mailer; bh=BVckrEST5WKAbfjBSU8qKTZNPC9o+URRyh+zhDduAgQ=; b=FXB4M1ZfgZSRYDUom8FI0E5+afORdWoHn6RbdkkwX3oGQm9QYh21JTLpvbKNH/KYKo 4V5vtpP3qhf7vjJLgzkRdowc/ggxQbNa9FBG7QQyr/pRne3bZRTcrU6dZKEOMpr4IqpB 3bEr0I1v90c3yYMajwqsSIenrgZ/QV8j5v48w= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:mime-version:content-type:subject:date:in-reply-to:to :references:message-id:x-mailer; b=lh8fW6PxZZKq2b8tVisdGh5S4MrBoHL7vAjY4ttcyiFnw+OwpOnrVChVK1LOA08diI kVNynA4rcrszjtXMjita41yi1z/MDmfN/Ly/ATPQ7j8i+r7BQBLsXSvDGQr0GMCz4QC7 k7fhuJs2AdB7SQA8ez4JAjbvnLQ57/vm9h6UY= Original-Received: by 10.216.67.15 with SMTP id i15mr5433228wed.32.1307563929934; Wed, 08 Jun 2011 13:12:09 -0700 (PDT) Original-Received: from [192.168.1.29] (118.24.85.79.rev.sfr.net [79.85.24.118]) by mx.google.com with ESMTPS id m8sm682503wbh.11.2011.06.08.13.12.08 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 08 Jun 2011 13:12:08 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.1084) X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=74.125.82.41; country=US; region=CA; city=Mountain View; postalcode=94043; latitude=37.4192; longitude=-122.0574; metrocode=807; areacode=650; http://maps.google.com/maps?q=37.4192,-122.0574&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 0xERwcaVz - 2380fb631985 - 20110608 X-Scanned-By: CanIt (www . roaringpenguin . com) on 194.171.167.221 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:68997 Archived-At: --===============2105790765== Content-Type: multipart/alternative; boundary=Apple-Mail-16-691729035 --Apple-Mail-16-691729035 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 Dear Hans, dear Mathieu, Thank you very much for your quick thoughts and solutions! It is amazing how fast one gets a solution to one's problem on this = list=85 Just a note for Mathieu: I think that \enableregime[il1] is not needed in mkiv, since a unicode regime is the default there = (however with mkii I use \enableregime[utf] but in the case we are discussing, one has to use lua, so mkiv is = mandatory). Best regards: OK On 8 juin 2011, at 19:00, Mathieu Dupont wrote: >=20 > This following code works, except that the first random is always the = same (Analysis) for some reason. >=20 > Anyone knows why ? >=20 > \enableregime[il1] > \starttext > \startluacode > userdata =3D 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=F6dinger = equation"}\par} > \stoptext >=20 >=20 >=20 > Mathieu >=20 >=20 >=20 >=20 > > From: otared@gmail.com > > Date: Wed, 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 mkiv > >=20 > > Hi all, > >=20 > > Assuming that we have a set of words or expressions, say > > {Maths, Physics, Algebra, Analysis, Chemistry, Geometry, Wave = equation, Schr=F6dinger equation} > > is it possible to write a lua function, named for instance > > randomselectword > > which returns one of the words or expressions selected at random in = the above 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, please add an = entry to the Wiki! > >=20 > > 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 > > = __________________________________________________________________________= _________ > = __________________________________________________________________________= _________ > If your question is of interest to others as well, please add an entry = to the Wiki! >=20 > 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 > = __________________________________________________________________________= _________ %%%%%%%%%%%%%%%%%% Otared Kavian D=E9partement de Math=E9matiques Universit=E9 de Versailles Saint-Quentin B=E2timent Fermat 45 avenue des Etats Unis 78035 Versailles cedex T=E9l=E9phone: +33 1 39 25 46 42 Secr=E9tariat: +33 1 39 25 46 44=20 Secr=E9tariat: +33 1 39 25 46 46 e-mail: Otared.Kavian@math.uvsq.fr --Apple-Mail-16-691729035 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=windows-1252 Dear = Hans, dear Mathieu,

Thank you very much for your = quick thoughts and solutions!
It is amazing how fast one gets = a solution to one's problem on this list=85

Just = a note for Mathieu: I think that
\enableregime[il1]
is = not needed in mkiv, since a unicode regime is the default there (however = with mkii I use
\enableregime[utf]
but = in the case we are discussing, one has to use lua, so mkiv is = mandatory).

Best regards: = OK


On 8 juin 2011, at 19: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 =3D userdata or = {}
= math.randomseed( os.time() )
function = userdata.random(...)
= context(arg[math.random(1, #arg)])
= end
\stopluacode
\def\CHOOSERANDOM#1{\ctxlua{us= erdata.random(#1)}}
\dorecurse{10}{\CHOOSERANDOM{"Maths", = "Physics", "Algebra", "Analysis", "Chemistry", "Geometry", "Wave = equation", "Schr=F6dinger = equation"}\par}
\stoptext



Mathieu




> = From: otared@gmail.com
> = Date: Wed, 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 = mkiv
>
> Hi all,
>
> Assuming that we have a = set of words or expressions, say
> {Maths, Physics, = Algebra, Analysis, Chemistry, Geometry, Wave equation, Schr=F6dinger = equation}
> is it possible to write a lua function, named for = instance
> randomselectword
> which returns one of = the words or expressions selected at random in the above set?
> = Indeed this is intended to be used in a TeX file processed with = mkiv.
>
> Thanks in advance for any idea and help.
> =
> Best regards: OK
> = __________________________________________________________________________= _________
> 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.sup= elec.fr/projects/contextrev/
> wiki : http://contextgarden.net
> = __________________________________________________________________________= _________
= __________________________________________________________________________= _________
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.sup= elec.fr/projects/contextrev/
wiki     : http://contextgarden.net
________= __________________________________________________________________________= _

%%%%%%%%%%%%%%%%%%
Otared = Kavian
D=E9partement de Math=E9matiques
Universit=E9 = de Versailles Saint-Quentin
B=E2timent Fermat
45 = avenue des Etats Unis
78035 Versailles = cedex

T=E9l=E9phone: +33 1 39 25 46 = 42
Secr=E9tariat: +33 1 39 25 46 = 44 
Secr=E9tariat: +33 1 39 25 46 = 46




= --Apple-Mail-16-691729035-- --===============2105790765== 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 ___________________________________________________________________________________ --===============2105790765==--