5.2 Using the random Fragment

A program using the random fragment will have the following structure:

INCLUDE '~beta/basiclib/random
--- program: descriptor ---
(# ...
   i: @integer;
do ...
   (123, 456) -> setsd;
   ...
   (1,100) -> inguin -> i;
   ...
#)

5.2.1 Illustrating Integer Random Generator

Program 5: tstign.bet

ORIGIN '~beta/basiclib/random';
--- program: descriptor ---
(# testIgn:
     (# iarray: [mxint]@integer;
        itmp: @integer;
        lo, hi, i, up: @integer
     do (for i:nrep repeat
             (1,mxint)->ignuin->itmp;
             itmp->screen.putint(# do 7->width #);
             (if (i mod 10) = 0 then newline if);
             iarray[itmp]+1->iarray[itmp];
        for);
        newline;
        '         Counts of Integers Generated:'->putline;
        (* Print 10 to a line using 7 characters for each field.         *)
        mxint->up; 1->lo;
        l: (if lo<=up then
               (lo+9,up)->min->hi;
               lo->i;
               ll: (if i<=hi then
                       iarray[i]->screen.putint(# do 7->width #);
                       i+1->i;
                       restart ll
                   if);
               screen.newline;
               lo+10->lo;
               restart l;
           if)
     #);
   
   mxint,nrep: @integer;

do ' Tests uniform random integer generator.'->putline; newline;
   
   ' Enter two seeds to initialize rn generator: '->puttext;
   (getint,getint)->setall;
      
   ' Enter maximum uniform integer: '->puttext;
   getint->mxint;

   ' Enter number of randoms to generate: '->puttext;
   getint->nrep;
   
   testIgn;
#)


Basic Libraries - Reference Manual
© 1990-2002 Mjølner Informatics
[Modified: Monday October 23rd 2000 at 11:49]