From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/73632 Path: news.gmane.org!not-for-mail From: "Meer, H. van der" Newsgroups: gmane.comp.tex.context Subject: Re: How to define a command... Date: Thu, 5 Jan 2012 20:11:21 +0000 Message-ID: References: <6457E519-6F30-482B-98DC-08BD546F8B2F@gmail.com> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1325794294 19292 80.91.229.12 (5 Jan 2012 20:11:34 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 5 Jan 2012 20:11:34 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Thu Jan 05 21:11:30 2012 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 1Riter-00050v-OQ for gctc-ntg-context-518@m.gmane.org; Thu, 05 Jan 2012 21:11:29 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id EBA29CB1E2; Thu, 5 Jan 2012 21:11:28 +0100 (CET) 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 fCrHp+XfQyht; Thu, 5 Jan 2012 21:11:26 +0100 (CET) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 0563BCB1D5; Thu, 5 Jan 2012 21:11:26 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 1FB7FCB1D5 for ; Thu, 5 Jan 2012 21:11:25 +0100 (CET) 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 8Uv9uTXluCtC for ; Thu, 5 Jan 2012 21:11:22 +0100 (CET) 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 DB3B1CB1D2 for ; Thu, 5 Jan 2012 21:11:22 +0100 (CET) Original-Received: from jansen.uva.nl (jansen.uva.nl [146.50.108.229]) by filter4-til.mf.surf.net (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id q05KBLjO021032 for ; Thu, 5 Jan 2012 21:11:22 +0100 Original-Received: from bijvoet.uva.nl (146.50.108.241) by jansen.uva.nl (146.50.108.229) with Microsoft SMTP Server (TLS) id 14.1.355.2; Thu, 5 Jan 2012 21:11:21 +0100 Original-Received: from ketelaar.uva.nl ([fe80::cc61:4c73:c438:df97]) by bijvoet.uva.nl ([::1]) with mapi id 14.01.0355.002; Thu, 5 Jan 2012 21:11:21 +0100 Thread-Topic: [NTG-context] How to define a command... Thread-Index: AQHMy+WB5kIl10Av0EuNqeHNuUdlApX+I9IA In-Reply-To: <6457E519-6F30-482B-98DC-08BD546F8B2F@gmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [82.95.102.36] Content-ID: <64FFB87972A9CB44B01A980DE3103079@uva.nl> X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=146.50.108.229; country=NL; region=07; city=Amsterdam; latitude=52.3500; longitude=4.9167; http://maps.google.com/maps?q=52.3500,4.9167&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 05GhUbmWM - 92962a0c2aab - 20120105 (trained as not-spam) X-Scanned-By: CanIt (www . roaringpenguin . com) on 194.171.167.220 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:73632 Archived-At: Reccently I did something random in ctxlua. I post it in the hope it will be useful. Hans van der Meer \startluacode -- Define our namespace as hvdm hvdm = hvdm or {} -- Return random series of numbers 1..n depending on the number of arguments function hvdm.randomseries (n, straight) local done = {} for i = 1, n do done[i] = i end if straight == "false" then return table.concat(done,",") end local result = "" for i = n, 2, -1 do local r = math.random(i) result = result .. done[r] .. "," table.remove(done,r) end result = result .. done[1] return result end \stopluacode \def\RandomSeed#1{\directlua{math.randomseed(#1)}} \def\RandomValue{\directlua{tex.print(math.random())}} \def\RandomRange#1{\directlua{tex.print(math.random(#1))}} \def\RandomSeries[#1]#2{\ctxlua{tex.print(hvdm.randomseries(#2,"#1"))}% On 5 jan. 2012, at 21:05, Otared Kavian wrote: > Hi all, > > I need to define numerical coefficients (essentially at random) and then use them with commands, say like \CoeffAlpha, \CoeffBeta, and so on. > More precisely, how can I define the command \RandomCoeff, so that \RandomCoeff{Beta}{1}{10} yields a command named \CoeffBeta, which is a random number chosen between 1 and 10? > > I tried to use the following approach, but could not make it work: > > %%% begin random-coeff.tex > \setuprandomize[2012] % set a seed > > \ctxlua{CoeffAlpha = math.random(1,10) ;} > \def\CoeffAlpha{\ctxlua{tex.print(CoeffAlpha)}} > > %%%%% > \define[3]\RandomCoeff{% > \ctxlua{a = math.random(#2,#3)} > % \csname{Coeff#1}\endcsname{\ctxlua{tex.print(a)}} %% this line does not work as expected... > } > > \starttext > \CoeffAlpha > > \RandomCoeff{Beta}{1}{10} > > \ctxlua{tex.print(a)} > > %\CoeffBeta > > \stoptext > %%% end random-coeff.tex > > Thanks in advance for any suggestion or hint. > 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.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! 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 ___________________________________________________________________________________