comp.lang.ada
 help / color / mirror / Atom feed
From: eachus@spectre.mitre.org (Robert I. Eachus)
Subject: Re: (no subject)
Date: 1998/11/13
Date: 1998-11-13T00:00:00+00:00	[thread overview]
Message-ID: <EACHUS.98Nov13170739@spectre.mitre.org> (raw)
In-Reply-To: 72hgcq$5d4$1@nnrp1.dejanews.com

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...




  reply	other threads:[~1998-11-13  0:00 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
  -- strict thread matches above, loose matches on Subject: below --
2006-01-23 15:56 Per Sandberg
2002-10-08  2:18 Rick Duley
2001-05-05 10:43 <no subject> Kent Paul Dolan
2001-05-05  8:25 Kent Paul Dolan
1999-09-15  0:00 (no subject) Justine O'Hara
1999-09-14  0:00 ` Keith Thompson
1997-08-18  0:00 Moustafa abdul wahab
1997-06-03  0:00 Matthew Daniel
1997-01-23  0:00 Mathieu POUPARDIN
1996-12-31  0:00 <no subject> Brad Dale
1996-12-31  0:00 Renegade
1996-06-07  0:00 (no subject) Mark Fisher
1996-04-15  0:00 Markus Knasmueller
1996-04-09  0:00 chico
1996-04-09  0:00 ` David Weller
1996-03-19  0:00 Mike Ibarra
replies disabled

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