texlive[54723] Master: random (13apr20)

commits+karl at tug.org commits+karl at tug.org
Mon Apr 13 23:38:38 CEST 2020


Revision: 54723
          http://tug.org/svn/texlive?view=revision&revision=54723
Author:   karl
Date:     2020-04-13 23:38:38 +0200 (Mon, 13 Apr 2020)
Log Message:
-----------
random (13apr20)

Modified Paths:
--------------
    trunk/Master/tlpkg/bin/tlpkg-ctan-check
    trunk/Master/tlpkg/tlpsrc/collection-plaingeneric.tlpsrc

Added Paths:
-----------
    trunk/Master/texmf-dist/doc/generic/random/
    trunk/Master/texmf-dist/doc/generic/random/README.md
    trunk/Master/texmf-dist/doc/generic/random/random-doc.pdf
    trunk/Master/texmf-dist/doc/generic/random/random-doc.tex
    trunk/Master/texmf-dist/tex/generic/random/
    trunk/Master/texmf-dist/tex/generic/random/random.tex
    trunk/Master/tlpkg/tlpsrc/random.tlpsrc

Added: trunk/Master/texmf-dist/doc/generic/random/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/generic/random/README.md	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/generic/random/README.md	2020-04-13 21:38:38 UTC (rev 54723)
@@ -0,0 +1,11 @@
+#random.tex      ver 0.2   (Donald Arseneau)
+
+Generating "random" numbers in TeX. 
+
+   `\setrannum {<`*counter*`>} {<`*minimum*`>} {<`*maximum*`>}`  
+   `\setrandimen {<`*dimen-register*`>} {<`*minimum*`>} {<`*maximum*`>}`
+
+This software is contributed to the public domain.
+
+Definitions are in `random.tex`. Documentation is in comments of
+`random.tex` and in `random-doc.tex` and `random-doc.pdf`


Property changes on: trunk/Master/texmf-dist/doc/generic/random/README.md
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/generic/random/random-doc.pdf
===================================================================
(Binary files differ)

Index: trunk/Master/texmf-dist/doc/generic/random/random-doc.pdf
===================================================================
--- trunk/Master/texmf-dist/doc/generic/random/random-doc.pdf	2020-04-13 21:36:45 UTC (rev 54722)
+++ trunk/Master/texmf-dist/doc/generic/random/random-doc.pdf	2020-04-13 21:38:38 UTC (rev 54723)

Property changes on: trunk/Master/texmf-dist/doc/generic/random/random-doc.pdf
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/pdf
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/generic/random/random-doc.tex
===================================================================
--- trunk/Master/texmf-dist/doc/generic/random/random-doc.tex	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/generic/random/random-doc.tex	2020-04-13 21:38:38 UTC (rev 54723)
@@ -0,0 +1,74 @@
+% plain TeX
+
+\def\cmd#1{\leavevmode\hbox{\tt\string#1}}
+\edef\{{\string{}
+\edef\}{\string}}
+
+\noindent{\bf RANDOM.TEX }\qquad\qquad  ver 0.2 \qquad\qquad  (Donald Arseneau)
+
+\bigskip
+
+\noindent Generating ``random'' numbers in \TeX. 
+
+\medskip
+
+  {\tt \string\setrannum \thinspace\{$\langle \it counter\rangle$\}\thinspace\{$\langle\it minimum\rangle$\}\thinspace\{$\langle\it maximum\rangle$\}}
+
+  {\tt \string\setrandimen \thinspace\{$\langle \hbox{\it dimen-register}\rangle$\}\thinspace\{$\langle\it minimum\rangle$\}\thinspace\{$\langle\it maximum\rangle$\}}
+
+\medskip
+\noindent This software is released to the public domain.
+\bigskip
+\noindent Random integers are generated in the range 1 to 2147483646 by the
+macro \cmd\nextrandom.  The result is returned in the counter \cmd\randomi.
+Do not change \cmd\randomi\ except, perhaps, to initialize it at some
+random (or specific) value.  If you do not initialize it, it will be initialized
+using the time and date.  (This is a sparse initialization, giving
+fewer than a million different starting values, but you should use
+other sources of numbers if they are available---just remember that
+most of the numbers available to \TeX\ are not at all random.)
+
+The \cmd\nextrandom\ command is not very useful by itself, unless you
+have exactly 2147483646 things to choose from.  Much more useful
+is the \cmd\setrannum\ command which sets a given counter to a random
+value within a specified range.  There are three parameters:
+\medskip
+{\tt \string\setrannum \thinspace\{$\langle \it counter\rangle$\}\thinspace\{$\langle\it minimum\rangle$\}\thinspace\{$\langle\it maximum\rangle$\}}
+\medskip
+\noindent For example, to simulate a die-roll:
+\medskip
+{\tt \string\setrannum\{\string\die\}\{1\}\{6\} \string\ifcase\string\die...}
+\medskip
+
+If you need random numbers that are not integers, you will have to
+use dimen registers instead with \cmd\setrandimen.  For example, to set a random
+page width between 3 and 6.5 inches:
+\medskip
+\cmd\setrandimen \cmd\hsize{\tt\{3in\}\{6.5in\}}
+\medskip\noindent
+The ``\cmd\pointless'' macro
+will remove the ``{\tt pt}'' that \TeX\ gives so you can use the dimensions
+as pure ``real'' numbers.  In that case, specify the range in {\tt pt} units.
+For example,
+\medskip
+   {\tt\string\setrandimen\string\answer\{2.71828pt\}\{3.14159pt\}}
+   \hfill\break\indent
+   {\tt The answer is \string\pointless\string\answer.}
+\medskip
+
+The random number generator is the one by Lewis, Goodman, and Miller
+(1969) and used as ``ran0'' in ``Numerical Recipies'' using Schrage's
+method for avoiding overflows.  The multiplier is 16807 ($7^5$), the
+added constant is 0, and the modulus is 2147483647 ($2^{31}-1$).
+
+See CACM, Vol.~36, no. 7, (July 1993), p.~109.  The original authors 
+Park and Miller have since concluded that a better multiplier is 48271,
+rather than their original 16807.
+
+The range of integers generated is $1 - 2147483646$.  A smaller range would
+reduce the complexity of the macros a bit, but not much---most of the
+code deals with initialization and type-conversion.  On the other hand,
+the large range may be wasted due to the sparse seed initialization.
+
+
+\bye


Property changes on: trunk/Master/texmf-dist/doc/generic/random/random-doc.tex
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/Master/texmf-dist/tex/generic/random/random.tex
===================================================================
--- trunk/Master/texmf-dist/tex/generic/random/random.tex	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/generic/random/random.tex	2020-04-13 21:38:38 UTC (rev 54723)
@@ -0,0 +1,104 @@
+% RANDOM.TEX       v 0.2   (Donald Arseneau)
+% Generating "random" numbers in TeX. 
+%
+% \setrannum {<counter>} {<minimum>} {<maximum>}
+% \setrandimen {<dimen-register>} {<minimum>} {<maximum>}
+%
+% This software is released to the public domain.
+%
+% Random integers are generated in the range 1 to 2147483646 by the
+% macro \nextrandom.  The result is returned in the counter \randomi.
+% Do not change \randomi except, perhaps, to initialize it at some
+% random value.  If you do not initialize it, it will be initialized
+% using the time and date.  (This is a sparse initialization, giving
+% fewer than a million different starting values, but you should use
+% other sources of numbers if they are available--just remember that
+% most of the numbers available to TeX are not at all random.)
+%
+% The \nextrandom command is not very useful by itself, unless you
+% have exactly 2147483646 things to choose from.  Much more useful
+% is the \setrannum command which sets a given counter to a random
+% value within a specified range.  There are three parameters:
+% \setrannum {<counter>} {<minimum>} {<maximum>}.  For example, to
+% simulate a die-roll: \setrannum{\die}{1}{6} \ifcase\die... .
+%
+% If you need random numbers that are not integers, you will have to
+% use dimen registers and \setrandimen.  For example, to set a random
+% page width: \setrandimen \hsize{3in}{6.5in}.  The "\pointless" macro
+% will remove the "pt" that TeX gives so you can use the dimensions
+% as pure `real' numbers.  In that case, specify the range in pt units.
+% For example,
+%   \setrandimen\answer{2.71828pt}{3.14159pt}
+%   The answer is \pointless\answer.
+%
+% The random number generator is the one by Lewis, Goodman, and Miller
+% (1969) and used as "ran0" in "Numerical Recipies" using Schrage's
+% method for avoiding overflows.  The multiplier is 16807 (7^5), the
+% added constant is 0, and the modulus is 2147483647 (2^{31}-1).
+%
+% See CACM, Vol. 36, no. 7, (July 1993), p. 109.  The original authors 
+% Park and Miller have since concluded that a better multiplier is 48271,
+% rather than their original 16807.
+%
+% The range of integers generated is 1 - 2147483646.  A smaller range would
+% reduce the complexity of the macros a bit, but not much--most of the
+% code deals with initialization and type-conversion.  On the other hand,
+% the large range may be wasted due to the sparse seed initialization.
+
+\newcount\randomi % the random number seed (while executing)
+\global\randomi\catcode`\@  % scratch variable during definitions
+\catcode`\@=11
+
+\def\nextrandom{\begingroup
+ \ifnum\randomi<\@ne % then initialize with time
+    \global\randomi\time
+    \global\multiply\randomi388 \global\advance\randomi\year
+    \global\multiply\randomi31 \global\advance\randomi\day
+    \global\multiply\randomi97 \global\advance\randomi\month
+    \message{Randomizer initialized to \the\randomi.}%
+    \nextrandom \nextrandom \nextrandom
+ \fi
+ \count at ii\randomi
+ \divide\count at ii 127773 % modulus = multiplier * 127773 + 2836
+ \count@\count at ii
+ \multiply\count at ii 127773
+ \global\advance\randomi-\count at ii % random mod 127773
+ \global\multiply\randomi 16807
+ \multiply\count@ 2836
+ \global\advance\randomi-\count@
+ \ifnum\randomi<\z@ \global\advance\randomi 2147483647\relax\fi
+ \endgroup
+}
+
+\countdef\count at ii=2 % use only in boxes!
+\ifx\@tempcnta\undefined \csname newcount\endcsname \@tempcnta \fi
+\ifx\@tempcntb\undefined \csname newcount\endcsname \@tempcntb \fi
+
+\def\setrannum#1#2#3{% count register, minimum, maximum
+ \@tempcnta#3\advance\@tempcnta-#2\advance\@tempcnta\@ne
+ \@tempcntb 2147483645 %  =  m - 2  =  2^{31} - 3
+ \divide\@tempcntb\@tempcnta
+ \getr at nval
+ \advance\ranval#2\relax
+ #1\ranval
+}
+
+\def\setrandim#1#2#3{% dimen register, minimum length, maximum length
+ \dimen@#2\dimen at ii#3\relax
+ \setrannum\ranval\dimen@\dimen at ii
+ #1\ranval sp\relax
+}
+
+\def\getr at nval{% The values in \@tempcnta and \@tempcntb are parameters
+ \nextrandom
+ \ranval\randomi \advance\ranval\m at ne \divide\ranval\@tempcntb
+ \ifnum\ranval<\@tempcnta\else \expandafter\getr at nval \fi
+}
+
+\def\pointless{\expandafter\PoinTless\the}
+{\catcode`p=12 \catcode`t=12 
+\gdef\PoinTless#1pt{#1}}
+
+\catcode`\@=\randomi
+\global\randomi=0
+\newcount\ranval


Property changes on: trunk/Master/texmf-dist/tex/generic/random/random.tex
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/tlpkg/bin/tlpkg-ctan-check
===================================================================
--- trunk/Master/tlpkg/bin/tlpkg-ctan-check	2020-04-13 21:36:45 UTC (rev 54722)
+++ trunk/Master/tlpkg/bin/tlpkg-ctan-check	2020-04-13 21:38:38 UTC (rev 54723)
@@ -616,7 +616,8 @@
      qualitype quantikz quantumarticle quattrocento quicktype quiz2socrative
      quotchap quoting quotmark
      quran quran-de quran-ur
-  r_und_s ragged2e raleway ran_toks randbild randomlist randomwalk randtext
+  r_und_s ragged2e raleway ran_toks randbild
+    random randomlist randomwalk randtext
     rank-2-roots rccol rcs rcs-multi rcsinfo
     readarray realboxes realhats realscripts rec-thy
     recipe recipebook recipecard recycle rectopma

Modified: trunk/Master/tlpkg/tlpsrc/collection-plaingeneric.tlpsrc
===================================================================
--- trunk/Master/tlpkg/tlpsrc/collection-plaingeneric.tlpsrc	2020-04-13 21:36:45 UTC (rev 54722)
+++ trunk/Master/tlpkg/tlpsrc/collection-plaingeneric.tlpsrc	2020-04-13 21:38:38 UTC (rev 54723)
@@ -77,6 +77,7 @@
 depend plstmary
 depend poormanlog
 depend present
+depend random
 depend randomlist
 depend resumemac
 depend ruler

Added: trunk/Master/tlpkg/tlpsrc/random.tlpsrc
===================================================================


More information about the tex-live-commits mailing list.