ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* A macro which gives a random name
@ 2015-04-18 16:55 Otared Kavian
  2015-04-18 17:23 ` Wolfgang Schuster
  0 siblings, 1 reply; 7+ messages in thread
From: Otared Kavian @ 2015-04-18 16:55 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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’t 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 = {'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[\NamedFunctionNumber])}}

\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) = 1$.\par \hairline\par}

\stoptext
%%%% begin random-names.tex
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-04-19  9:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-18 16:55 A macro which gives a random name Otared Kavian
2015-04-18 17:23 ` Wolfgang Schuster
2015-04-18 19:16   ` Otared Kavian
2015-04-18 20:24   ` Otared Kavian
2015-04-18 20:36     ` Hans Hagen
2015-04-19  7:51       ` Otared Kavian
2015-04-19  9:55         ` Hans Hagen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).