Skip to content

Commit

Permalink
Document the new rnglib features in Appendix G of the Unicon book.
Browse files Browse the repository at this point in the history
  • Loading branch information
Don-Ward committed Mar 22, 2022
1 parent 11942aa commit b0722a8
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions doc/book/experimental.tex
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,42 @@ \section{Extensions to \texttt{\&random}}
This feature allows the programmer to choose from a portfolio of different
random number generators (in addition to the one provided by Icon). It is also
possible to implement other generators and use them without rebuilding Unicon.
More than one generator may be in use at the same time.
It may be enabled by defining the C preprocessor symbol \texttt{RngLibrary}
before rebuilding the Unicon system.
More than one generator may be in use at the same time. It may be enabled by
using the \texttt{-{}-enable-rnglibs} option to \texttt{configure} before
rebuilding the Unicon system.

If the extension is enabled four new standard functions are defined:
\bigskip\hrule\vspace{0.1cm}
\noindent
{\bf loadrng(s) : string? } \hfill {\bf load PRNG}

\noindent
\texttt{loadrng(s)} replaces the generator in use by the current thread with the generator
denoted by \texttt{s}. \texttt{loadrng("rngIcon")} will reload the default generator.
\texttt{loadrng()} returns the name of the generator in use. The \texttt{?} operator will
use the loaded generator to produce random numbers.

\bigskip\hrule\vspace{0.1cm}
\noindent
{\bf rngbits(i) : array? } \hfill {\bf return random bits}

\noindent
\texttt{rngbits(n)} returns an integer array that contains at least \texttt{n} randomly
generated bits. If \texttt{n} is negative no bits are returned but the generator will skip
ahead as if the bits were actually returned. If \texttt{n} is zero it is an invitation to
supply the ``natural size'' of the generator (which is probably a power of two).

\bigskip\hrule\vspace{0.1cm}
\noindent
{\bf rngbitstring(i) : string? } \hfill {\bf return random bits}

\noindent
\texttt{rngbitstring(n)} returns a string that contains \texttt{n}
randomly generated \texttt{0} and \texttt{1} characters.

\bigskip\hrule\vspace{0.1cm}
\noindent
{\bf rngval() : integer? } \hfill {\bf return random value}

\noindent
\texttt{rngval()} returns a randomly generated integer value.

0 comments on commit b0722a8

Please sign in to comment.