\manpage {random\_source} {} {Random Sources} 
 
\definition 
An instance of type \name\ is a random source. It allows to generate
uniformly distributed random bits, characters, integers, and doubles.
It can be in  either of two modes: In bit mode it generates a random bit string
of some given length $p$ ($1 \le p \le 31$) and in integer mode it generates a random
integer in some given range $[ low .. high]$  ($low \le high < low + 2^{31}$). The mode can be changed any time, either globally or for a single operation. The output of the random
source can be converted to a number of formats (using standard conversions).
 
\creation S 
 
\create { }
   { creates an instance \var\ of type \name ,
             puts it into bit mode, and 
             sets the precision to 31.  }
 
 
\create {(int\ p)}
   { creates an instance \var\ of type \name ,
             puts it into bit mode, and 
             sets the precision to $p$ ($1 \le p \le 31$).  }
 
 
\create {(int\ low,\ int\ high)}
   { creates an instance \var\ of type \name ,
             puts it into integer mode, and 
             sets the range to $[ low .. high]$.  }
 
 
\operations 3.2 5 
 
\op  void set\_seed {(int\ s)}
           {  resets the seed of the random number generator to $s$.  }
 
 
\opl void set\_range {(int\ low, \ int\ high)}
           {  sets the mode to integer mode and
                changes the range to $[ low .. high]$.  }
 
 
\op  void set\_precision {(int\ p)}
           {  sets the mode to bit mode and
                changes the precision to $p$ bits.  }
 
 
\binop random\_source\& >> {char\&\ x}
         {  extracts a character $x$ of default precision or range
                and returns \var, i.e., it first generates an unsigned
                integer of the desired precision or in the desired range
                and then converts it to a character (by standard conversion).
                  }
 
 
\binop random\_source\& >> {unsigned\ char\&\ x}
         {  extracts an unsigned character $x$ of default precision or
                range and returns \var.  }
 
 
\binop random\_source\& >> {int\&\ x}
         {  extracts an integer $x$ of default precision or range and
                returns \var.  }
 
 
\binop random\_source\& >> {unsigned\ int\&\ x}
         {  extracts an unsigned integer $x$ of default precision or
                range and returns \var.  }
 
 
\binop random\_source\& >> {double\&\ x}
         {  extracts a real number $x$ in $[0,1]$, i.e,
                $u/(2^{31} -1)$ where $u$ is a random integer in 
                $[0..2^{31}-1]$,
                and returns \var. }
 
 
\binop random\_source\& >> {bool\&\ b}
         {  extracts a random boolean value (true or false).  }
 
 
\op  unsigned get {()}
           {  returns an unsigned integer of maximal precision (31 bits).  }
 
 
\funop int  {}
         {  returns an integer $x$. }
 
 
\funop int  {int\ prec}
         {  returns an integer $x$ of supplied precision $prec$.  }
 
 
\funop int  {int\ low, \ int\ high}
         {  returns an integer $x$ from the supplied range $[low..high]$.  }
 
 
