comp.lang.ada
 help / color / mirror / Atom feed
From: jmatthews@nova.wright.edu (Dr. John B. Matthews)
Subject: Re: random number generation -> PLEASE HELP!
Date: 1996/09/05
Date: 1996-09-05T00:00:00+00:00	[thread overview]
Message-ID: <1996Sep5.165031@nova.wright.edu> (raw)
In-Reply-To: vi8k9uh3r59.fsf@fnal.gov


In article <vi8k9uh3r59.fsf@fnal.gov>, Oleg Krivosheev <kriol@fnal.gov> writes:
> ica2ph@alpha1.csv.ica.uni-stuttgart.de (Peter Hermann) writes:
>> Justin Vandenbroucke (rva036@lulu.acns.nwu.edu) wrote:
>> : Does anyone know how to generate "random" numbers in pascal?  I know BASIC
>> : has a standard function that does it, and I know there is some actual code
>> 
>> Ada95, the natural successor of Pascal, has a standard function, of course.
>> see http://lglwww.epfl.ch/Ada/
> 
> C, the natural successor of assembler, has it too... And who cares?
> THere are no words in standard about required rnd genertor quality, so
> it's hardly usefull for anything but (simple) games

Nonsense. GNAT (the GNU Ada compiler from NYU; http://www.gnat.com/)
and MacOS (http://www.apple.com) have very satisfactory psuedo-
random number generators. The former is available in source from
ftp://ftp.cs.nyu.edu/pub/gnat; the latter is shown below.

unit ACMRandom;

interface

   procedure SetACMSeed (seed: LongInt);
   function ACMRandom: LongInt;

implementation

   var
      acmRandSeed: LongInt; {static variable}

   procedure SetACMSeed (seed: LongInt);
   begin
      if seed = 0 then
         seed := 1;
      if seed < 0 then
         seed := -seed;
      acmRandSeed := seed;
   end;

   function ACMRandom: LongInt;
{"minimal standard random number generator" proposed by}
{Parker & Miller in CACM, 1988; it has period (2^31)-1}
      var
         lo, hi, test: LongInt;
   begin
      hi := acmRandSeed div 127773;
      lo := acmRandSeed mod 127773;
      test := 16807 * lo - 2836 * hi;
      if test > 0 then
         acmRandSeed := test
      else
         acmRandSeed := test + maxLongInt;
      ACMRandom := acmRandSeed;
   end;

end.

program RandomTest;

   uses
      QuickDraw, ACMRandom;

   var
      i: Integer;

begin
   randSeed := 123456789;
   SetACMSeed(randSeed);
   for i := 1 to 25 do
      WriteLn(Random : 7, randSeed : 12, ACMRandom : 12);
end.

John
----------------------------------------------------------------
Dr. John B. Matthews
jmatthews@nova.wright.edu; john_matthews@ccmail.dayton.saic.com
"Whom the gods would destroy, they first invite to program in C"





       reply	other threads:[~1996-09-05  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <rva036-2208962255270001@aragorn189.nuts.nwu.edu>
     [not found] ` <vi8k9uh3r59.fsf@fnal.gov>
1996-09-05  0:00   ` Dr. John B. Matthews [this message]
1996-09-06  0:00     ` random number generation -> PLEASE HELP! Philip Brashear
1996-09-08  0:00     ` Uri Raz
1996-09-10  0:00       ` Richard A. O'Keefe
1996-09-06  0:00   ` Robert I. Eachus
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox