comp.lang.ada
 help / color / mirror / Atom feed
* (no subject)
@ 1998-11-13  0:00 niel.williams
  1998-11-13  0:00 ` Random Number Generator John Herro
  1998-11-13  0:00 ` (no subject) dennison
  0 siblings, 2 replies; 7+ messages in thread
From: niel.williams @ 1998-11-13  0:00 UTC (permalink / raw)


Has any one got a simple random number
generator prog that generates numbers
between 1-10





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

* Random Number Generator
  1998-11-13  0:00 (no subject) niel.williams
@ 1998-11-13  0:00 ` John Herro
  1998-11-13  0:00 ` (no subject) dennison
  1 sibling, 0 replies; 7+ messages in thread
From: John Herro @ 1998-11-13  0:00 UTC (permalink / raw)



"niel.williams" <niel.williams@virgin.net> writes:
> Has any one got a simple random number
> generator prog that generates numbers
> between 1-10?

If you have an Ada 95 compiler, the answer is simply to use the package
Ada.Numerics.Discrete_Random, which comes with the language.  This program
keeps displaying random integers from 1 to 10:

with Ada.Text_IO, Ada.Numerics.Discrete_Random;
use  Ada.Text_IO;
procedure Test is
  subtype S is Integer range 1 .. 10;
  package My_Random is new
       Ada.Numerics.Discrete_Random(S);
  use My_Random;
  G : Generator;
begin
  Reset(G);
  loop
    Put(Integer'Image(Random(G)));
  end loop;
end Test;

If you have an Ada 83 compiler, the answer is much more complicated, but the
compiler *may* have come with a package to do what you want.

- John Herro
You can download a shareware Ada Tutor program at
http://members.aol.com/AdaTutor




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

* Re: (no subject)
  1998-11-13  0:00 (no subject) niel.williams
  1998-11-13  0:00 ` Random Number Generator John Herro
@ 1998-11-13  0:00 ` dennison
  1998-11-13  0:00   ` Robert I. Eachus
  1 sibling, 1 reply; 7+ messages in thread
From: dennison @ 1998-11-13  0:00 UTC (permalink / raw)


In article <364C0C41.6CC14A8C@virgin.net>,
  "niel.williams" <niel.williams@virgin.net> wrote:
> Has any one got a simple random number
> generator prog that generates numbers
> between 1-10

Ada.Numerics.Discrete_Random


--
T.E.D.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: (no subject)
  1998-11-13  0:00 ` (no subject) dennison
@ 1998-11-13  0:00   ` Robert I. Eachus
  0 siblings, 0 replies; 7+ messages in thread
From: Robert I. Eachus @ 1998-11-13  0:00 UTC (permalink / raw)


In article <72hgcq$5d4$1@nnrp1.dejanews.com> dennison@telepath.com writes:

  > Ada.Numerics.Discrete_Random

  Good answer, but there is a typo/bug in gnat 3.10p and some earlier
versions that causes it to generate biased results. This program will
show you if you have the problem, if the values for the three doors
are not approximately equal.  (The fix is trivial, correct the sign in
the line below, but cause confusion by broadcasting a non-CM version
of the package. Of course, if you fix the installed version you have
to recompile it with -gnatg.)


  if TF > Flt (Rst'Pos (Rst'Last)) + 0.5 then
         return Rst'First;


----------------------------------------------------------------------------

with Discrete_Random;
with Ada.Numerics.Float_Random;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
procedure Random_Bug is
   Tries: constant := 10000;
   Wins, Switch_Wins, Offers: Integer := 0;
   type Doors is (Door1, Door2, Door3);
   package Select_Door is new Discrete_Random(Doors);
   Door_Gen: Select_Door.Generator;
   function Random_Door(Gen: in Select_Door.Generator := Door_Gen)
           return Doors renames Select_Door.Random;
   Float_Gen: Ada.Numerics.Float_Random.Generator;
   function Rand(Gen: in Ada.Numerics.Float_Random.Generator :=
Float_Gen)
           return Float renames Ada.Numerics.Float_Random.Random;
   Door_Counts: array(Doors) of Integer := (0,0,0);
   Old_Door, New_Door: Doors;
begin

   Select_Door.Reset(Door_Gen);
   Old_Door := Random_Door;
   for Test in 1..8 loop
     Door_Counts := (0,0,0);
     Wins := 0;
     for I in 1..Tries loop
       New_Door := Random_Door;
       Door_Counts(New_Door) := Door_Counts(New_Door) + 1;
       if New_Door = Old_Door then Wins := Wins + 1; end if;
       Old_Door := New_Door;
     end loop;
     Put (" Door 1: " & Integer'Image(Door_Counts(Door1)));
     Put (" Door 2: " & Integer'Image(Door_Counts(Door2)));
     Put (" Door 3: " & Integer'Image(Door_Counts(Door3)));
     New_Line;
     Put (" Wins: " & Integer'Image(Wins));
     New_Line(2);
   end loop;
  
end Random_Bug;

--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




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

* Re: Random Number Generator
  2000-02-26  0:00 Random Number Generator Hustler
@ 2000-02-26  0:00 ` David C. Hoos, Sr.
  2000-02-28  0:00 ` Robert Dewar
  1 sibling, 0 replies; 7+ messages in thread
From: David C. Hoos, Sr. @ 2000-02-26  0:00 UTC (permalink / raw)



Hustler <bdowney@wvu.edu> wrote in message
news:8981l1$1dfqk$1@homer.cfw.com...
> Does anyone know where the number generator is located, ie the package? Is
> it in ada.elementary_functions packages or do I need to find a package
that
> contains a random number generator?
For pseudo-random floating-point random numbers, it's in the package
Ada.Numerics.Float_Random.  For pseudo-random integers and enumeration type
it's in the package Ada.Numerics.Discrete_Random.








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

* Random Number Generator
@ 2000-02-26  0:00 Hustler
  2000-02-26  0:00 ` David C. Hoos, Sr.
  2000-02-28  0:00 ` Robert Dewar
  0 siblings, 2 replies; 7+ messages in thread
From: Hustler @ 2000-02-26  0:00 UTC (permalink / raw)


Does anyone know where the number generator is located, ie the package? Is
it in ada.elementary_functions packages or do I need to find a package that
contains a random number generator?

Thanks for the help
Brandon






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

* Re: Random Number Generator
  2000-02-26  0:00 Random Number Generator Hustler
  2000-02-26  0:00 ` David C. Hoos, Sr.
@ 2000-02-28  0:00 ` Robert Dewar
  1 sibling, 0 replies; 7+ messages in thread
From: Robert Dewar @ 2000-02-28  0:00 UTC (permalink / raw)


In article <8981l1$1dfqk$1@homer.cfw.com>,
  "Hustler" <bdowney@wvu.edu> wrote:
> Does anyone know where the number generator is located, ie the
package? Is
> it in ada.elementary_functions packages or do I need to find a
package that
> contains a random number generator?
>
> Thanks for the help
> Brandon


Here's how you can answer a straightforward question like this
instantaneously for yourself.

Get an electronic copy of the Ada 95 RM (you can find this at
www.adapower.com for example).

Then search for the string "random" or else look up Random
in the index. Either approach will lead you to the appropriate
package immediately.


Sent via Deja.com http://www.deja.com/
Before you buy.




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

end of thread, other threads:[~2000-02-28  0:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-11-13  0:00 (no subject) niel.williams
1998-11-13  0:00 ` Random Number Generator John Herro
1998-11-13  0:00 ` (no subject) dennison
1998-11-13  0:00   ` Robert I. Eachus
  -- strict thread matches above, loose matches on Subject: below --
2000-02-26  0:00 Random Number Generator Hustler
2000-02-26  0:00 ` David C. Hoos, Sr.
2000-02-28  0:00 ` Robert Dewar

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