summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.random.code.tex
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.random.code.tex')
-rw-r--r--Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.random.code.tex260
1 files changed, 129 insertions, 131 deletions
diff --git a/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.random.code.tex b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.random.code.tex
index 531383dfdcd..44b8ef8f6ef 100644
--- a/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.random.code.tex
+++ b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.random.code.tex
@@ -7,7 +7,7 @@
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.
-% This file defines the pseudorandom numbers.
+% This file defines the pesudorandom numbers.
%
% Version 1.414213 29/9/2007
@@ -15,8 +15,8 @@
%
% See:
% \book@{pressetal1992,
-% author = {William H. Press and Brian P. Flannery and Saul A.
-% Teukolsky and William T. Vetterling},
+% author = {William H. Press and Brian P. Flannery and Saul A.
+% Teukolsky and William T. Vetterling},
% title = {Numerical Recipies in C},
% edition = {Second},
% publisher = {Cambridge University Press}
@@ -30,26 +30,23 @@
\begingroup
\c@pgfmath@counta=\time%
\multiply\c@pgfmath@counta by\year%
-\ifnum\c@pgfmath@counta=0
- \c@pgfmath@counta=1
-\fi
-\xdef\pgfmath@rnd@z{\the\c@pgfmath@counta}% The seed.
+\xdef\pgfmath@rnd@z{\the\c@pgfmath@counta}% The seed.
\endgroup
% \pgfmathsetseed
%
-% Explicitly set the seed for the generator
-%
+% Explictly set the seed for the generator
+%
% #1 -> the new seed.
%
\def\pgfmathsetseed#1{%
- % Attention pgflibraryluamath.code.tex relies on the fact that
- % this method also modifies \pgfmathresult:
- \pgfmathparse{#1}\expandafter\pgfmath@setseed\pgfmathresult.0\pgfmath@stop
+ % Attention pgflibraryluamath.code.tex relies on the fact that
+ % this method also modifies \pgfmathresult:
+ \pgfmathparse{#1}\expandafter\pgfmath@setseed\pgfmathresult.0\pgfmath@stop
}%
-\def\pgfmath@setseed#1.#2\pgfmath@stop{\def\pgfmath@rnd@z{#1}}%
+\def\pgfmath@setseed#1.#2\pgfmath@stop{\def\pgfmath@rnd@z{#1}}%
-% Alternative parameters - see Press et al (1992) p278-279,
+% Alternative paramaters - see Press et al (1992) p278-279,
% for discussion.
%
% a=16807 q=127773 r=2836
@@ -60,33 +57,33 @@
\def\pgfmath@rnd@q{30845}
% \pgfmathgeneratepseudorandomnumber
-%
+%
% A linear congruency generator for generating
% pseudo-random numbers. Generates numbers in
% the range 1 - 2^31-1.
%
\def\pgfmathgeneratepseudorandomnumber{%
- \begingroup%
- \c@pgfmath@counta=\pgfmath@rnd@z%
- \c@pgfmath@countb=\pgfmath@rnd@z%
- \c@pgfmath@countc=\pgfmath@rnd@q%
- \divide\c@pgfmath@counta by\c@pgfmath@countc%
- \multiply\c@pgfmath@counta by-\c@pgfmath@countc%
- \advance\c@pgfmath@counta by\c@pgfmath@countb
- \c@pgfmath@countc=\pgfmath@rnd@a%
- \multiply\c@pgfmath@counta by\c@pgfmath@countc%
- \c@pgfmath@countc=\pgfmath@rnd@q%
- \divide\c@pgfmath@countb by\c@pgfmath@countc%
- \c@pgfmath@countc=\pgfmath@rnd@r%
- \multiply\c@pgfmath@countb by\c@pgfmath@countc%
- \advance\c@pgfmath@counta by-\c@pgfmath@countb%
- \ifnum\c@pgfmath@counta<0\relax%
- \c@pgfmath@countb=\pgfmath@rnd@m%
- \advance\c@pgfmath@counta by\c@pgfmath@countb%
- \fi%
- \xdef\pgfmath@rnd@z{\the\c@pgfmath@counta}%
- \endgroup%
- \edef\pgfmathresult{\pgfmath@rnd@z}%
+ \begingroup%
+ \c@pgfmath@counta=\pgfmath@rnd@z%
+ \c@pgfmath@countb=\pgfmath@rnd@z%
+ \c@pgfmath@countc=\pgfmath@rnd@q%
+ \divide\c@pgfmath@counta by\c@pgfmath@countc%
+ \multiply\c@pgfmath@counta by-\c@pgfmath@countc%
+ \advance\c@pgfmath@counta by\c@pgfmath@countb
+ \c@pgfmath@countc=\pgfmath@rnd@a%
+ \multiply\c@pgfmath@counta by\c@pgfmath@countc%
+ \c@pgfmath@countc=\pgfmath@rnd@q%
+ \divide\c@pgfmath@countb by\c@pgfmath@countc%
+ \c@pgfmath@countc=\pgfmath@rnd@r%
+ \multiply\c@pgfmath@countb by\c@pgfmath@countc%
+ \advance\c@pgfmath@counta by-\c@pgfmath@countb%
+ \ifnum\c@pgfmath@counta<0\relax%
+ \c@pgfmath@countb=\pgfmath@rnd@m%
+ \advance\c@pgfmath@counta by\c@pgfmath@countb%
+ \fi%
+ \xdef\pgfmath@rnd@z{\the\c@pgfmath@counta}%
+ \endgroup%
+ \edef\pgfmathresult{\pgfmath@rnd@z}%
}
% \pgfmathrnd
@@ -94,22 +91,22 @@
% Generates a pseudo-random number between 0 and 1.
%
\pgfmathdeclarefunction{rnd}{0}{%
- \begingroup%
- \pgfmathgeneratepseudorandomnumber%
- \c@pgfmath@counta\pgfmathresult%
- \c@pgfmath@countb\c@pgfmath@counta%
- \divide\c@pgfmath@countb100001\relax% To get one.
- \multiply\c@pgfmath@countb-100001\relax%
- \advance\c@pgfmath@countb\c@pgfmath@counta%
- \advance\c@pgfmath@countb1000000\relax%
- \expandafter\pgfmathrnd@@\the\c@pgfmath@countb\pgfmath@%
- \pgfmath@returnone\pgfmath@x%
- \endgroup%
+ \begingroup%
+ \pgfmathgeneratepseudorandomnumber%
+ \c@pgfmath@counta\pgfmathresult%
+ \c@pgfmath@countb\c@pgfmath@counta%
+ \divide\c@pgfmath@countb100001\relax% To get one.
+ \multiply\c@pgfmath@countb-100001\relax%
+ \advance\c@pgfmath@countb\c@pgfmath@counta%
+ \advance\c@pgfmath@countb1000000\relax%
+ \expandafter\pgfmathrnd@@\the\c@pgfmath@countb\pgfmath@%
+ \pgfmath@returnone\pgfmath@x%
+ \endgroup%
}%
\def\pgfmathrnd@@#1#2#3\pgfmath@{%
- \edef\pgfmath@temp{#2.#3}%
- \pgfmath@x=\pgfmath@temp pt\relax%
+ \edef\pgfmath@temp{#2.#3}%
+ \pgfmath@x=\pgfmath@temp pt\relax%
}%
% \pgfmathrand
@@ -117,57 +114,57 @@
% Generates a pseudo-random number between -1 and 1.
%
\pgfmathdeclarefunction{rand}{0}{%
- \begingroup%
- \pgfmathgeneratepseudorandomnumber%
- \c@pgfmath@counta\pgfmathresult%
- \c@pgfmath@countb\c@pgfmath@counta%
- \divide\c@pgfmath@countb200001\relax%
- \multiply\c@pgfmath@countb-200001\relax%
- \advance\c@pgfmath@countb\c@pgfmath@counta%
- \advance\c@pgfmath@countb-100000\relax%
- \ifnum\c@pgfmath@countb<0\relax%
- \advance\c@pgfmath@countb-1000000\relax%
- \else%
- \advance\c@pgfmath@countb1000000\relax%
- \fi%
- \expandafter\pgfmathrand@@\the\c@pgfmath@countb\pgfmath@%
- \pgfmath@returnone\pgfmath@x%
- \endgroup%
+ \begingroup%
+ \pgfmathgeneratepseudorandomnumber%
+ \c@pgfmath@counta\pgfmathresult%
+ \c@pgfmath@countb\c@pgfmath@counta%
+ \divide\c@pgfmath@countb200001\relax%
+ \multiply\c@pgfmath@countb-200001\relax%
+ \advance\c@pgfmath@countb\c@pgfmath@counta%
+ \advance\c@pgfmath@countb-100000\relax%
+ \ifnum\c@pgfmath@countb<0\relax%
+ \advance\c@pgfmath@countb-1000000\relax%
+ \else%
+ \advance\c@pgfmath@countb1000000\relax%
+ \fi%
+ \expandafter\pgfmathrand@@\the\c@pgfmath@countb\pgfmath@%
+ \pgfmath@returnone\pgfmath@x%
+ \endgroup%
}%
\def\pgfmathrand@@#1#2#3#4\pgfmath@{%
- \ifx#1-%
- \edef\pgfmath@temp{-#3.#4}%
- \else%
- \edef\pgfmath@temp{#2.#3#4}%
- \fi%
- \pgfmath@x=\pgfmath@temp pt\relax%
+ \ifx#1-%
+ \edef\pgfmath@temp{-#3.#4}%
+ \else%
+ \edef\pgfmath@temp{#2.#3#4}%
+ \fi%
+ \pgfmath@x=\pgfmath@temp pt\relax%
}%
\pgfmathdeclarefunction{random}{...}{%
- \begingroup%
- \def\pgfmath@temp{#1}%
- \ifx\pgfmath@temp\pgfmath@empty%
- \pgfmathrnd@%
- \else%
- \expandafter\pgfmathrandom@@#1\pgfmath@stop%
- \fi%
- \pgfmath@smuggleone\pgfmathresult%
- \endgroup}
+ \begingroup%
+ \def\pgfmath@temp{#1}%
+ \ifx\pgfmath@temp\pgfmath@empty%
+ \pgfmathrnd@%
+ \else%
+ \expandafter\pgfmathrandom@@#1\pgfmath@stop%
+ \fi%
+ \pgfmath@smuggleone\pgfmathresult%
+ \endgroup}
\def\pgfmathrandom@@{\futurelet\pgfmath@token\pgfmathrandom@@@}
\def\pgfmathrandom@@@{%
- \ifx\pgfmath@token\bgroup%
- \expandafter\pgfmath@random@@@@%
- \else%
- \expandafter\pgfmath@random@@@@@%
- \fi%
+ \ifx\pgfmath@token\bgroup%
+ \expandafter\pgfmath@random@@@@%
+ \else%
+ \expandafter\pgfmath@random@@@@@%
+ \fi%
}
\def\pgfmath@random@@@@@#1\pgfmath@stop{%
- \pgfmathrandominteger\pgfmathresult{1}{#1}%
+ \pgfmathrandominteger\pgfmathresult{1}{#1}%
}
\def\pgfmath@random@@@@#1#2\pgfmath@stop{%
- \pgfmathrandominteger\pgfmathresult{#1}{#2}%
+ \pgfmathrandominteger\pgfmathresult{#1}{#2}%
}
% \pgfmathrandominteger
@@ -179,29 +176,29 @@
% #3 - the upper limit of the range.
%
\def\pgfmathrandominteger#1#2#3{%
- \begingroup%
- \pgfmathgeneratepseudorandomnumber%
- \c@pgfmath@counta#2\relax%
- \c@pgfmath@countb#3\relax%
- \c@pgfmath@countc\c@pgfmath@countb%
- % OK. Maybe #2 > #3.
- \ifnum\c@pgfmath@counta>\c@pgfmath@countb\relax%
- \c@pgfmath@countc\c@pgfmath@countb%
- \c@pgfmath@countb\c@pgfmath@counta%
- \c@pgfmath@counta\c@pgfmath@countc%
- \fi%
- \advance\c@pgfmath@countc1\relax%
- \advance\c@pgfmath@countc-\c@pgfmath@counta%
- \c@pgfmath@counta\pgfmathresult\relax%
- \c@pgfmath@countb\c@pgfmath@counta%
- \divide\c@pgfmath@countb\c@pgfmath@countc%
- \multiply\c@pgfmath@countb-\c@pgfmath@countc%
- \advance\c@pgfmath@counta\c@pgfmath@countb%
- \advance\c@pgfmath@counta#2\relax%
- \edef\pgfmathresult{\the\c@pgfmath@counta}%
- \pgfmath@smuggleone{\pgfmathresult}%
- \endgroup%
- \edef#1{\pgfmathresult}%
+ \begingroup%
+ \pgfmathgeneratepseudorandomnumber%
+ \c@pgfmath@counta#2\relax%
+ \c@pgfmath@countb#3\relax%
+ \c@pgfmath@countc\c@pgfmath@countb%
+ % OK. Maybe #2 > #3.
+ \ifnum\c@pgfmath@counta>\c@pgfmath@countb\relax%
+ \c@pgfmath@countc\c@pgfmath@countb%
+ \c@pgfmath@countb\c@pgfmath@counta%
+ \c@pgfmath@counta\c@pgfmath@countc%
+ \fi%
+ \advance\c@pgfmath@countc1\relax%
+ \advance\c@pgfmath@countc-\c@pgfmath@counta%
+ \c@pgfmath@counta\pgfmathresult\relax%
+ \c@pgfmath@countb\c@pgfmath@counta%
+ \divide\c@pgfmath@countb\c@pgfmath@countc%
+ \multiply\c@pgfmath@countb-\c@pgfmath@countc%
+ \advance\c@pgfmath@counta\c@pgfmath@countb%
+ \advance\c@pgfmath@counta#2\relax%
+ \edef\pgfmathresult{\the\c@pgfmath@counta}%
+ \pgfmath@smuggleone{\pgfmathresult}%
+ \endgroup%
+ \edef#1{\pgfmathresult}%
}
% \pgfmathdeclarerandomlist
@@ -212,24 +209,24 @@
% #2 - a list of comma separated elements.
%
\def\pgfmathdeclarerandomlist#1#2{%
- \def\pgfmath@randomlistname{#1}%
- \begingroup%
- \c@pgfmath@counta=1\relax%
- % {} is a possible random element so (locally)
- % redefine \pgfmath@empty.
- \def\pgfmath@empty{pgfmath@empty}%
- \expandafter\pgfmath@scanrandomlist#2{pgfmath@empty}}
+ \def\pgfmath@randomlistname{#1}%
+ \begingroup%
+ \c@pgfmath@counta=1\relax%
+ % {} is a possible random element so (locally)
+ % redefine \pgfmath@empty.
+ \def\pgfmath@empty{pgfmath@empty}%
+ \expandafter\pgfmath@scanrandomlist#2{pgfmath@empty}}
\def\pgfmath@scanrandomlist#1{%
- \def\pgfmath@scanneditem{#1}%
- \ifx\pgfmath@scanneditem\pgfmath@empty%
- \advance\c@pgfmath@counta-1\relax%
- \expandafter\xdef\csname pgfmath@randomlist@\pgfmath@randomlistname\endcsname{\the\c@pgfmath@counta}%
- \endgroup%
- \else%
- \expandafter\gdef\csname pgfmath@randomlist@\pgfmath@randomlistname @\the\c@pgfmath@counta\endcsname{#1}%
- \advance\c@pgfmath@counta1\relax%
- \expandafter\pgfmath@scanrandomlist%
- \fi}
+ \def\pgfmath@scanneditem{#1}%
+ \ifx\pgfmath@scanneditem\pgfmath@empty%
+ \advance\c@pgfmath@counta-1\relax%
+ \expandafter\xdef\csname pgfmath@randomlist@\pgfmath@randomlistname\endcsname{\the\c@pgfmath@counta}%
+ \endgroup%
+ \else%
+ \expandafter\gdef\csname pgfmath@randomlist@\pgfmath@randomlistname @\the\c@pgfmath@counta\endcsname{#1}%
+ \advance\c@pgfmath@counta1\relax%
+ \expandafter\pgfmath@scanrandomlist%
+ \fi}
% \pgfmathrandomitem
%
@@ -239,7 +236,8 @@
% #2 - the name of the list.
%
\def\pgfmathrandomitem#1#2{%
- \pgfmath@ifundefined{pgfmath@randomlist@#2}{\pgfmath@error{Unknown random list `#2'}}{%
- \edef\pgfmath@randomlistlength{\csname pgfmath@randomlist@#2\endcsname}%
- \pgfmathrandominteger{\pgfmath@randomtemp}{1}{\pgfmath@randomlistlength}%
- \def#1{\csname pgfmath@randomlist@#2@\pgfmath@randomtemp\endcsname}}}
+ \pgfmath@ifundefined{pgfmath@randomlist@#2}{\pgfmath@error{Unknown random list `#2'}}{%
+ \edef\pgfmath@randomlistlength{\csname pgfmath@randomlist@#2\endcsname}%
+ \pgfmathrandominteger{\pgfmath@randomtemp}{1}{\pgfmath@randomlistlength}%
+ \def#1{\csname pgfmath@randomlist@#2@\pgfmath@randomtemp\endcsname}}}
+