From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bf23cb25158d2486 X-Google-Attributes: gid103376,public From: eachus@spectre.mitre.org (Robert I. Eachus) Subject: Re: (no subject) Date: 1998/11/13 Message-ID: #1/1 X-Deja-AN: 411596580 References: <364C0C41.6CC14A8C@virgin.net> <72hgcq$5d4$1@nnrp1.dejanews.com> Organization: The Mitre Corp., Bedford, MA. Newsgroups: comp.lang.ada Date: 1998-11-13T00:00:00+00:00 List-Id: 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...