% $Id: pst-math.sty 859 2018-12-13 15:31:03Z herbert $
%%
%% This is file `pst-math.sty'.
%%
%% IMPORTANT NOTICE:
%%
%% pst-math Copyright (C) 2019-     Herbert Voss <hvoss@tug.org>
%%
%% This package may be distributed under the terms of the LaTeX Project
%% Public License, as described in lppl.txt in the base LaTeX distribution.
%% Either version 1.0 or, at your option, any later version.
%%

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{pst-math}[2018/12/13 v 0.64package wrapper for PSTricks pst-math.tex]
\RequirePackage{pst-calculate}
\input pst-math.tex
\ProvidesFile{pst-math.tex}
  [\filedate\space v\fileversion\space `PST-math' (hv)]
\IfFileExists{pst-math.pro}{\ProvidesFile{pst-math.pro}%
    [2018/12/13 v. 0.64,  PostScript prologue file (hv)]
\@addtofilelist{pst-math.pro}}{}%

\newcounter{Rand@No}\newcounter{Random@Left}\newcounter{Random@Right}\newcounter{Random@No@max}%
\setcounter{Rand@No}{0}\setcounter{Random@Left}{1}\setcounter{Random@Right}{1000}%

\def\defineRandIntervall(#1,#2)#3{%
  \setcounter{Random@Left}{#1}%
  \setcounter{Random@Right}{#2}%
  \setcounter{Random@No@max}{#3}%
  \setcounter{Rand@No}{0}%
  \def\RandomNumbers{}%
}

\def\RandomNumbers{}%\pscalculate{randint(\theRandom@Left,\theRandom@Right)}}

\def\makeSimpleRandomNumberList{%
  \def\RandomNumbers{}%
  \psforeach{\iA}{1,2,..,\theRandom@No@max}{%
    \edef\@Number{\pscalculate{randint(\theRandom@Left,\theRandom@Right)}}% Zufallszahl
    \ifnum\iA=1
      \xdef\RandomNumbers{\@Number}%
    \else
      \xdef\RandomNumbers{\RandomNumbers,\@Number}%
    \fi
%    \typeout{\RandomNumbers}%
  }%
}
%
\def\makeRandomNumberList{%
  \edef\@Number{\pscalculate{randint(\theRandom@Left,\theRandom@Right)}}% Zufallszahl
  \ifnum\theRand@No=\z@
    \xdef\RandomNumbers{\@Number}%
    \stepcounter{Rand@No}%
    \xdef\@Number{\pscalculate{randint(\theRandom@Left,\theRandom@Right)}}% Zufallszahl
  \fi
  \add@Number{\@Number}\RandomNumbers!!}

\def\add@Number#1#2!!{\edef\x{\noexpand\add@Number@i#1;#2,,\relax}\x}
\def\add@Number@i#1;#2,#3,#4\relax{%
  \ifx\relax#2\relax % we found new number
    \xdef\RandomNumbers{\RandomNumbers,#1}%
    \stepcounter{Rand@No}%
    \ifnum\theRand@No>\theRandom@No@max
      \def\next{}% Neue Zahl?
    \else 
      \def\next{\makeRandomNumberList}
    \fi%
  \else
    \ifnum#1=#2 % no new number
      \def\next{\makeRandomNumberList}%
    \else 
      \ifx\relax#3\relax 
        \def\next{\add@Number@i#1;,,\relax}%
      \else %
        \def\next{\add@Number@i#1;#3,#4\relax}%
      \fi
    \fi
  \fi
  \ifnum\theRand@No<\theRandom@No@max \next \fi
}
\def\getNumberFromList#1{%
  \global\count0 = 1
  \edef\x{\noexpand\get@Index#1;\RandomNumbers}\x,,\relax}
\def\get@Index#1;#2,#3,#4\relax{%
  \ifnum\the\count0=#1 
    \def\next{#2}%
  \else
    \global\advance\count0 by 1
    \def\next{\get@Index#1;#3,#4\relax}%
  \fi
  \next
}


\endinput
