From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/91117 Path: news.gmane.org!not-for-mail From: Otared Kavian Newsgroups: gmane.comp.tex.context Subject: Re: A macro which gives a random name Date: Sat, 18 Apr 2015 21:16:47 +0200 Message-ID: <9596E5D7-A917-42AE-A182-08D134E1D505@gmail.com> References: <6DC048B9-D53F-46B3-973D-C25FD93D3C27@gmail.com> <088338A7-A713-415A-9DF5-26804CDA9C7F@gmail.com> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2098\)) Content-Type: multipart/mixed; boundary="===============0404114320==" X-Trace: ger.gmane.org 1429384661 5044 80.91.229.3 (18 Apr 2015 19:17:41 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 18 Apr 2015 19:17:41 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Sat Apr 18 21:17:27 2015 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([5.39.185.229]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YjYF4-0000xG-Dz for gctc-ntg-context-518@m.gmane.org; Sat, 18 Apr 2015 21:17:26 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 8CA3610222 for ; Sat, 18 Apr 2015 21:17:25 +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 u-qGOUKj1W_o for ; Sat, 18 Apr 2015 21:17:24 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [IPv6:::1]) by balder.ntg.nl (Postfix) with ESMTP id BDE6710233 for ; Sat, 18 Apr 2015 21:16:55 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id D0E66101FA for ; Sat, 18 Apr 2015 21:16:52 +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 BqGKQBCh6f2e for ; Sat, 18 Apr 2015 21:16:51 +0200 (CEST) Original-Received: from filter1-utr.mf.surf.net (filter1-utr.mf.surf.net [195.169.124.152]) by balder.ntg.nl (Postfix) with ESMTP id 8324D101F9 for ; Sat, 18 Apr 2015 21:16:51 +0200 (CEST) Original-Received: from mail-wi0-x235.google.com (mail-wi0-x235.google.com [IPv6:2a00:1450:400c:c05::235]) by filter1-utr.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id t3IJGomZ024441 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Sat, 18 Apr 2015 21:16:50 +0200 Original-Received: by wicmx19 with SMTP id mx19so11615376wic.1 for ; Sat, 18 Apr 2015 12:16:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-type:message-id:mime-version:subject:date:references :to:in-reply-to; bh=ZkV+/spUdP1vXF0e7Q6DgGOxJg4a/T6rnj/jC27i2/A=; b=1DCVEbOfzFRc9e3ncHPDDRESJe6nSrMtQ4knAQFJaG/h4nSE07Ufz93mHbSQGLtxNr 1PdA7+wpE2Vzt8z2g93tBVuLDDc7baHdGOWKCp0vHli+QA+yWWnvQMgK4ekHOhzFCBwx RUTdH5cZ1QtGl7NmmetrFjCRvhj52GiSXb2fWJhfDF/z+2AKGhdJfGKQeRx8q6GkJ5OO 7JsTJQ73iAg+vOvTIbu79PEocLr7CbTQeE28ZxYzo5P8csIzsLOs/UBBlw1bzBTXlv7v wOo4EN4RWCg7oY7ycRhoZS4CveD2ahimhxPE3R8vSjzZDLPhB83bwfWAXI4sydLRiSj4 eIsA== X-Received: by 10.194.236.225 with SMTP id ux1mr17099037wjc.52.1429384610085; Sat, 18 Apr 2015 12:16:50 -0700 (PDT) Original-Received: from [192.168.0.102] (lns-bzn-60-82-254-207-71.adsl.proxad.net. [82.254.207.71]) by mx.google.com with ESMTPSA id pv2sm20061373wjc.33.2015.04.18.12.16.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 18 Apr 2015 12:16:49 -0700 (PDT) In-Reply-To: <088338A7-A713-415A-9DF5-26804CDA9C7F@gmail.com> X-Mailer: Apple Mail (2.2098) X-Bayes-Prob: 0.0001 (Score 0, tokens from: ntg-context@ntg.nl, base:default, @@RPTN) X-CanIt-Geo: ip=2a00:1450:400c:c05::235; country=IE; latitude=53.3478; longitude=-6.2597; http://maps.google.com/maps?q=53.3478,-6.2597&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 07OhvgOwJ - ee678b3042f2 - 20150418 Received-SPF: pass (filter1-utr.mf.surf.net: domain of otared@gmail.com designates 2a00:1450:400c:c05::235 as permitted sender) receiver=filter1-utr.mf.surf.net; client-ip=2a00:1450:400c:c05::235; envelope-from=; helo=mail-wi0-x235.google.com; identity=mailfrom X-Scanned-By: CanIt (www . roaringpenguin . com) X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.16 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.org gmane.comp.tex.context:91117 Archived-At: --===============0404114320== Content-Type: multipart/alternative; boundary="Apple-Mail=_FBE02566-2EC6-4404-AC77-DFC56B07FAEF" --Apple-Mail=_FBE02566-2EC6-4404-AC77-DFC56B07FAEF Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi Wolfgang, Thanks for your attention, but the problem with your solution is that = each instance of \RandomFunctionName changes the name chosen, but I need = something wihich remains the same name within a given situation (say = each problem) but changes from problem to problem.=20 For instance when using your solution with the source code Give an example of a function $\RandomFunctionName : {\Bbb R} = \longrightarrow {\Bbb R}$ which has a=20 derivative only at the origin, and such that = $\RandomFunctionName(0) =3D 1$. gives: Give an example of a function =F0=9D=90=BA : R =E2=9F=B6 R which = has a derivative only at the origin, and such that =F0=9D=91=8A(0) =3D = 1.=20 while what I need is=20 Give an example of a function =F0=9D=90=BA : R =E2=9F=B6 R which = has a derivative only at the origin, and such that G(0) =3D 1.=20 (The macro I sent earlier does this, but unfortunately it cannot use the = solution you sent). Is there a solution ? Best regards: OK > On 18 Apr 2015, at 19:23, Wolfgang Schuster = wrote: >=20 >=20 >> Am 18.04.2015 um 18:55 schrieb Otared Kavian : >>=20 >> Hi everyone, >>=20 >> In the example below I define a macro which chooses at random a name = from a list of names. But I wonder whether this can be done in a more = clever way without using a numerical macro created with math.random in = Lua. The shortcoming of the macro below is that before hand I must know = the nomber of elements in the list of names (for instance 5 in the = example below), while it may happen that I need to create as many as = random names that there are elements in the list, but sometimes I = don=E2=80=99t know what is this number. >>=20 >> Thanks for any insight and help. >> Best regards: OK >> %%%% begin random-names.tex >> \setuprandomize[2015] % set a seed >>=20 >> \starttext >>=20 >> \startluacode >> Name =3D {'F', 'G', 'u', 'v', 'W'} >> \stopluacode >>=20 >> \define[3]\RandomName{% >> \setevalue{Named#1}{\ctxlua{tex.print(math.random(#2,#3))}}} >> = \define\RandomFunctionName{\ctxlua{tex.print(Name[\NamedFunctionNumber])}}= >>=20 >> \dorecurse{10}{\RandomName{FunctionNumber}{1}{5}% >> Give an example of a function $\RandomFunctionName : {\Bbb R} = \longrightarrow {\Bbb R}$ which has a derivative only at the origin, and = such that $\RandomFunctionName(0) =3D 1$.\par \hairline\par} >>=20 >> \stoptext >> %%%% begin random-names.tex >=20 > You can access the size of your Name table with #Name but have to = replace # with \letterhash when you use it in a TeX command because # is = already taken for the TeX arguments. >=20 > \starttext >=20 > \startluacode > Name =3D {'F', 'G', 'u', 'v', 'W'} > \stopluacode >=20 > \define\RandomFunctionName > {\startlua > local listsize =3D \letterhash Name ; > local randomvalue =3D math.random(1,listsize) ; > context(Name[randomvalue]) > \stoplua} >=20 > \dorecurse{10}{Give an example of a function $\RandomFunctionName : = {\Bbb R} \longrightarrow {\Bbb R}$ which has a derivative only at the = origin, and such that $\RandomFunctionName(0) =3D 1$.\par \hairline\par} >=20 > \stoptext >=20 > Wolfgang >=20 > = __________________________________________________________________________= _________ > 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 > = __________________________________________________________________________= _________ --Apple-Mail=_FBE02566-2EC6-4404-AC77-DFC56B07FAEF Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Hi Wolfgang,

Thanks for your attention, but the problem with your solution = is that each instance of \RandomFunctionName changes the name chosen, = but I need something wihich remains the same name within a given = situation (say each problem) but changes from problem to = problem. 

For instance when using your solution with the source = code

Give an = example of a function $\RandomFunctionName : {\Bbb R} \longrightarrow = {\Bbb R}$ which has a 
= derivative only at the origin, and such that = $\RandomFunctionName(0) =3D 1$.
gives:
Give an = example of a function =F0=9D=90=BA : R =E2=9F=B6 R = which has a derivative only at the origin, and such that =F0=9D=91=8A(0) =3D 1

while what I need is 
= Give an = example of a function =F0=9D=90=BA : R =E2=9F=B6 = R which has a derivative only at the origin, and such = that G(0) =3D 1

(The macro I sent earlier = does this, but unfortunately it cannot use the solution you = sent).
Is there a solution ?

Best regards: = OK

On = 18 Apr 2015, at 19:23, Wolfgang Schuster <schuster.wolfgang@gmail.com> wrote:


Am 18.04.2015 um 18:55 = schrieb Otared Kavian <otared@gmail.com>:

Hi = everyone,

In the example below I define a = macro which chooses at random a name from a list of names. But I wonder = whether this can be done in a more clever way without using a numerical = macro created with math.random in Lua. The shortcoming of the macro = below is that before hand I must know the nomber of elements in the list = of names (for instance 5 in the example below), while it may happen that = I need to create as many as random names that there are elements in the = list, but sometimes I don=E2=80=99t know what is this number.

Thanks for any insight and help.
Best regards: OK
%%%% begin random-names.tex
\setuprandomize[2015] % set a seed

\starttext

\startluacode
= Name =3D {'F', 'G', 'u', 'v', 'W'}
\stopluacode

\define[3]\RandomName{%
= \setevalue{Named#1}{\ctxlua{tex.print(math.random(#2,#3))}}}
\define\RandomFunctionName{\ctxlua{tex.print(Name[\NamedFunctio= nNumber])}}

\dorecurse{10}{\RandomName{FunctionNumber}{1}{5}%
Give an example of a function $\RandomFunctionName : {\Bbb R} = \longrightarrow {\Bbb R}$ which has a derivative only at the origin, and = such that $\RandomFunctionName(0) =3D 1$.\par \hairline\par}

\stoptext
%%%% begin = random-names.tex

You can = access the size of your Name table with #Name but have to replace # with = \letterhash when you use it in a TeX command because # is already taken = for the TeX arguments.

\starttext

\startluacode
Name =3D = {'F', 'G', 'u', 'v', 'W'}
\stopluacode

\define\RandomFunctionName
 {\startlua
  local listsize    =3D \letterhash = Name ;
  local randomvalue =3D = math.random(1,listsize) ;
=   context(Name[randomvalue])
=   \stoplua}

\dorecurse{10}{Give = an example of a function $\RandomFunctionName : {\Bbb R} \longrightarrow = {\Bbb R}$ which has a derivative only at the origin, and such that = $\RandomFunctionName(0) =3D 1$.\par \hairline\par}

\stoptext

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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
_______________________________________________________________= ____________________

= --Apple-Mail=_FBE02566-2EC6-4404-AC77-DFC56B07FAEF-- --===============0404114320== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly90ZXguYWFuaGV0Lm5ldAphcmNoaXZlICA6IGh0dHA6Ly9mb3VuZHJ5LnN1cGVsZWMu ZnIvcHJvamVjdHMvY29udGV4dHJldi8Kd2lraSAgICAgOiBodHRwOi8vY29udGV4dGdhcmRlbi5u ZXQKX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX18= --===============0404114320==--