supp-ran.mkii / last modification: 2020-01-30 14:15
%D \module
%D   [       file=supp-ran,
%D        version=1998.01.21,
%D          title=\CONTEXT\ Support Macros,
%D       subtitle=Random Number Generation,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Support Macros / Random Number Generation}

%D \macros
%D   {getrandomcount, getrandomdimen,
%D    getrandomfloat, getrandomnumber,
%D    setrandomseed, getrandomseed}
%D This module load Donald Arseneau's generic file
%D \type{random.tex}. A small shell is needed because we
%D redefine some \TEX\ primitives. We also use different names
%D for the two generators and add an extra one.
%D \starttyping
%D \getrandomcount  \countregister {minimum} {maximum}
%D \getrandomdimen  \dimenregister {minimum} {maximum}
%D \getrandomnumber \macroname     {minimum} {maximum}
%D \getrandomfloat  \macroname     {minimum} {maximum}
%D \stoptyping
%D Of course the file \type{random.tex} needs to be present.
%D To prevent name clashes, the \CONTEXT\ distribution
%D contains a copy in \type {thrd-ran.tex}.
%D The randomseed can be set by:
%D \starttyping
%d \setrandomseed{number>0}
%D \stoptyping
%D and get by:
%D \starttyping
%D \getrandomseed\randomseed
%D \stoptyping

\input thrd-ran.mkii



       \let\time \normaltime
       \let\day  \normalday
       \let\year \normalyear


    \writestatus{loading}{using TeX's built in randomizer (overloading macro)}

    % For the meaning of the magic number, see \type {thrd-ran.tex}.
    % Taco suggested to use the following alternative because \type
    % {\uniformdeviate} can return a zero (as expected) while
    % Donalds Arseneau's alternative has a minimum of~1.






     \nextrandom \global\chardef\randomseedfrozen\plusone

     \global\chardef\randomseedfrozen\zerocount \nextrandom




\unexpanded \def\setrandomseed#1%
  {\global\randomi#1\relax} % global added

\unexpanded \def\getrandomseed#1%

  {\setrandomseed\minusone  % signals thrd-ran to auto reseed
   \nextrandom              % this signal is needed for the
   #1\randomi}              % pseudo randomizer (see: third-ran)