comp.lang.ada
 help / color / mirror / Atom feed
* Random numbers in Gnat
@ 1995-03-01 21:51 ab
  1995-03-02  8:31 ` Dave Marshall
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: ab @ 1995-03-01 21:51 UTC (permalink / raw)



I cannot find any discussion of the use of random() procedure
in gnat-2.03 Unix version for SunOS 4.1.3. The only information
that I found is in file a-numran.ads, and as the following
shows I must have misunderstood the intent and use of the objects
in that file.

Here is a little test that I've concocted:

        with text_io; use text_io;
		with ada.numerics.random; use ada.numerics.random;
		procedure randtest is
          package int_io is new integer_io(integer); use int_io;

		  rand_state: state:= make_state;

          -- return random number in 0..up_bound
          function my_random(up_bound: integer) return integer is
                r: Uniformly_Distributed;
          begin
                random( rand_state, r);
                return integer(r*float(up_bound));
          end my_random;          
        begin
          for i in 1..10 loop
                put(my_random(1000)); new_line;
          end loop;
        end randtest;

The program prints out only zeros rather than 10 random numbers in the
0..1000 range. I dislike the use of the global rand_state variable. 
However using it as a parameter is no better either. Indeed, why
should one be bothered with this quantity anyway? (In C one
just seeds the generator, and then calls the random() as a 
parameterless function, why not here?)

I'll appreciate your discussion as to how the random number
generator should be used. Pointers to some documentation/discussion
of the objects in a-numran.ads would also be helpful.

ab

-- 

Dr. A.Bykat
Fuller E. Callaway Professor




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1995-03-03 19:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-03-01 21:51 Random numbers in Gnat ab
1995-03-02  8:31 ` Dave Marshall
1995-03-03 19:11   ` Robert Dewar
1995-03-02 15:50 ` Robert I. Eachus
1995-03-03 15:08 ` Tucker Taft

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