     with ConsAK ; use ConsAK ; -- for Pause, Demo
     with FloaAK ; use FloaAK ;
     with InteAK ; use InteAK ;
     with Text_IO; use Text_IO;

     package body A83_017_Random is
     ----------------------------------------------------------------------
     ----------------------------------------------------------------------

     procedure Demo is
     ----------------------------------------------------------------------
     begin
       Put_Line ( Copyright );
       Put_Line ( Description );
       Put_Line ( "" );
       Put_Line ( "   -- Mean" );
       Put_Line ( "   -- Random_1" );
       Put_Line ( "   -- Variance" );
       Put_Line ( "" );
       declare
	 Generate : natural := 10_000;
	 Sum      : float := 0.0;
	 Seed     : Random_Seed_Type;
	 R        : float;
       begin
	 Generate := Ask_Nat (
	   "How many random numbers would you like to generate? ",
	   Generate );
	 for Index in 1..Generate loop
	   Random_1 ( R, Seed );
	   Sum := Sum + R;
	   Put ( natural'image ( Index ) );
	   Put ( "  Random_1: " );
	   Put ( R );
	   Put ( "  Average: " );
	   Put ( Sum / float ( Index ) );
	   Put_Line ( "" );
	 end loop;
	 Put_Line ( "" );
	 Pause;
       end;
     end Demo;

     function Mean (
       V : Vector_Type )
       return float is
     ----------------------------------------------------------------------
     begin
       return Sum ( V ) / float ( V'last - V'first + 1 );
     end Mean;

     procedure Random_1 (
       Random :    out float;
       Seed   : in out Random_Seed_Type ) is
     ---------------------------------------------------------------------------
       M1  : constant long_integer := 259_200;
       IA1 : constant long_integer :=   7_141;
       IC1 : constant long_integer :=  54_773;
       RM1 : constant float        := 1.0 / float ( M1 );
       M2  : constant long_integer := 134_456;
       IA2 : constant long_integer :=   8_121;
       IC2 : constant long_integer :=  28_411;
       RM2 : constant float        := 1.0 / float ( M2 );
       M3  : constant long_integer := 243_000;
       IA3 : constant long_integer :=   4_561;
       IC3 : constant long_integer :=  51_349;
       J   :          long_integer;
       Temp:          float;
     begin
       if Seed.IDum < 0 then
	 Seed.Glix1 := ( IC1 - Seed.IDum ) mod M1;
	 Seed.Glix1 := ( IA1 * Seed.Glix1 + IC1 ) mod M1;
	 Seed.Glix2 := Seed.Glix1 mod M2;
	 Seed.Glix1 := ( IA1 * Seed.Glix1 + IC1 ) mod M1;
	 Seed.Glix3 := Seed.Glix1 mod M3;
	 for index in Seed.Glr'range loop
	   Seed.Glix1 := ( IA1 * Seed.Glix1 + IC1 ) mod M1;
	   Seed.Glix2 := ( IA2 * Seed.Glix2 + IC2 ) mod M2;
	   Seed.Glr ( index ) := ( float ( Seed.Glix1 )
	     + float ( Seed.Glix2 ) * RM2 ) * RM1;
	 end loop;
     -- I added the next line.
	 Seed.IDum := 0;
       end if;
       Seed.Glix1 := ( IA1 * Seed.Glix1 + IC1 ) mod M1;
       Seed.Glix2 := ( IA2 * Seed.Glix2 + IC2 ) mod M2;
       Seed.Glix3 := ( IA3 * Seed.Glix3 + IC3 ) mod M3;
       J := 1 + ( 97 * Seed.Glix3 ) / M3;
       if ( J > 97 ) or ( J < 1 ) then
	 Pause ( "Pause in routine RAN1" );
       end if;
       Temp := Seed.Glr ( J );
       Seed.Glr ( J ) := ( float ( Seed.Glix1 )
	 + float ( Seed.Glix2 ) * RM2 ) * RM1;
       Random := Temp;
     end Random_1;

     function Variance (
       V : Vector_Type )
       return float is
     ----------------------------------------------------------------------
       M    : float;
       Temp : float := 0.0;
     begin
       M := Mean ( V );
       for Index in V'range loop
	 Temp := Temp + ( V ( Index ) - M ) ** 2;
       end loop;
       Temp := Temp / float ( V'last - V'first + 1 );
       return Temp;
     end Variance;

     ----------------------------------------------------------------------
     ----------------------------------------------------------------------
     end A83_017_Random;
