1%D \module 2%D [ file=supp-ran, 3%D version=2008-10-31, 4%D title=\CONTEXT\ Support Macros, 5%D subtitle=Random Number Generation, 6%D author=Hans Hagen, 7%D date=\currentdate, 8%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] 9%C 10%C This module is part of the \CONTEXT\ macro||package and is 11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for 12%C details. 13 14\writestatus{loading}{ConTeXt Support Macros / Random Number Generation} 15 16%D This module is downward compatible in the sense that we've kept the user 17%D interface (which uses intermediate variables). 18%D 19%D \starttyping 20%D \type{new}: \dorecurse{10}{\randomnumber{1}{100} }\par 21%D \setrandomseed{24}\type{set}: \dorecurse{10}{\randomnumber{1}{100} }\par 22%D \setrandomseed{24}\type{set}: \dorecurse{10}{\randomnumber{1}{100} }\par 23%D \setrandomseed{24}\type{set}: \dorecurse{10}{\randomnumber{1}{100} }\par 24%D \pushrandomseed \type{new}: \dorecurse{10}{\randomnumber{1}{100} }\par 25%D \poprandomseed \type{old}: \dorecurse{10}{\randomnumber{1}{100} }\par 26%D \type{new}: \dorecurse{10}{\randomnumber{1}{100} }\par 27%D \stoptyping 28 29\registerctxluafile{supp-ran}{} 30 31\unprotect 32 33\protected\def\getrandomcount #1#2#3{#1=\clf_getrandomnumber\numexpr#2\relax\numexpr#3\relax\relax} 34\protected\def\getrandomdimen #1#2#3{#1=\clf_getrandomdimen\dimexpr#2\relax\dimexpr#3\relax\scaledpoint\relax} 35\protected\def\getrandomnumber#1#2#3{\edef#1{\clf_getrandomnumber\numexpr#2\relax\numexpr#3\relax}} 36\protected\def\getrandomfloat #1#2#3{\edef#1{\clf_getrandomfloat\dimexpr#2\relax\dimexpr#3\relax}} 37\protected\def\setrandomseed #1{\clf_setrandomseed\numexpr#1\relax} 38\protected\def\getrandomseed #1{\edef#1{\clf_getrandomseed}} 39\protected\def\newrandomseed {\clf_getrandomseed} 40%protected\def\pushrandomseed {\clf_pushrandomseed} 41%protected\def\poprandomseed {\clf_poprandomseed} 42%protected\def\reuserandomseed {\clf_reuserandomseed} % within push/pop 43 44\let\freezerandomseed \pushrandomseed 45\let\defrostrandomseed\poprandomseed 46 47\setnewconstant \mpscaledmax 4095 % for old times sake 48 49\def\randomnumber #1#2{\clf_getrandomnumber\numexpr#1\relax\numexpr#2\relax} 50\def\mprandomnumber {\clf_getrandomnumber\zerocount\mpscaledmax} 51 52\protect \endinput 53 |