[BACK]Return to ts_random.adb CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / PHC / Ada / Math_Lib / Numbers

File: [local] / OpenXM_contrib / PHC / Ada / Math_Lib / Numbers / ts_random.adb (download)

Revision 1.1.1.1 (vendor branch), Sun Oct 29 17:45:26 2000 UTC (23 years, 7 months ago) by maekawa
Branch: PHC, MAIN
CVS Tags: v2, maekawa-ipv6, RELEASE_1_2_3, RELEASE_1_2_2_KNOPPIX_b, RELEASE_1_2_2_KNOPPIX, RELEASE_1_2_2, RELEASE_1_2_1, HEAD
Changes since 1.1: +0 -0 lines

Import the second public release of PHCpack.

OKed by Jan Verschelde.

with text_io,integer_io;                 use text_io,integer_io;
with Standard_Floating_Numbers;          use Standard_Floating_Numbers;
with Standard_Floating_Numbers_io;       use Standard_Floating_Numbers_io;
with Standard_Complex_Numbers;
with Standard_Complex_Numbers_io;        use Standard_Complex_Numbers_io;
with Standard_Random_Numbers;            use Standard_Random_Numbers;
with Multprec_Natural_Numbers;           use Multprec_Natural_Numbers;
with Multprec_Natural_Numbers_io;        use Multprec_Natural_Numbers_io;
with Multprec_Integer_Numbers;           use Multprec_Integer_Numbers;
with Multprec_Integer_Numbers_io;        use Multprec_Integer_Numbers_io;
with Multprec_Floating_Numbers;          use Multprec_Floating_Numbers;
with Multprec_Floating_Numbers_io;       use Multprec_Floating_Numbers_io;
with Multprec_Complex_Numbers;
with Multprec_Complex_Numbers_io;        use Multprec_Complex_Numbers_io;
with Multprec_Random_Numbers;            use Multprec_Random_Numbers;

procedure ts_random is

  procedure Random_Standard_Integer is

    n : natural;
    low,upp,rndi : integer;

  begin
    new_line;
    put_line("Testing the random generation of standard integer numbers.");
    new_line;
    put("Give lower bound : "); get(low);
    put("Give lower bound : "); get(upp);
    put("Give number of random integers : "); get(n);
    put_line("Generating random numbers : ");
    for i in 1..n loop
      rndi := Random(low,upp);
      put(rndi); new_line;
    end loop;
  end Random_Standard_Integer;

  procedure Random_Standard_Complex is

    n : natural;
    use Standard_Complex_Numbers;
    rndc : Complex_Number;
    absv : double_float;

  begin
    new_line;
    put_line("Testing the random generation of standard complex numbers.");
    new_line;
    put("Give the number of randoms to be generated : "); get(n);
    for k in 1..n loop
      rndc := Random;
      put(" x = "); put(rndc); 
      absv := AbsVal(rndc);
      put("   |x| = "); put(absv,3,3,3); new_line;
    end loop;
  end Random_Standard_Complex;

  procedure Random_Multprec_Natural is

    n,sz : natural;
    rnd : Natural_Number;

  begin
    new_line;
    put_line("Testing the random generation of multi-precision naturals.");
    new_line;
    put("Give the size of the numbers : "); get(sz);
    put("Give number of random naturals : "); get(n);
    put_line("Generating random numbers : ");
    for i in 1..n loop
      rnd := Random(sz); put(rnd); new_line;
    end loop;
  end Random_Multprec_Natural;

  procedure Random_Multprec_Integer is

    n,sz : natural;
    rnd : Integer_Number;

  begin
    new_line;
    put_line("Testing the random generation of multi-precision integers.");
    new_line;
    put("Give the size of the numbers : "); get(sz);
    put("Give number of random integers : "); get(n);
    put_line("Generating random numbers : ");
    for i in 1..n loop
      rnd := Random(sz); put(rnd); new_line;
    end loop;
  end Random_Multprec_Integer;

  procedure Random_Multprec_Floating is

    n,sz : natural;
    rnd : Floating_Number;

  begin
    new_line;
    put_line("Testing the random generation of multi-precision floats.");
    new_line;
    put("Give the size of the numbers : "); get(sz);
    put("Give number of random floating numbers : "); get(n);
    put_line("Generating random numbers : ");
    for i in 1..n loop
      rnd := Random(sz); put(rnd); new_line;
    end loop;
  end Random_Multprec_Floating;

  procedure Random_Multprec_Complex is

    n,sz : natural;
    use Multprec_Complex_Numbers;
    rnd : Complex_Number;

  begin
    new_line;
    put_line("Testing the random generation of multi-precision complex");
    new_line;
    put("Give the size of the numbers : "); get(sz);
    put("Give number of random complex numbers : "); get(n);
    put_line("Generating random numbers : ");
    for i in 1..n loop
      rnd := Random(sz); put(rnd); new_line;
    end loop;
  end Random_Multprec_Complex;

  procedure Main is

    ans : character;

  begin
    new_line;
    put_line("Testing the Random Number Generators");
    loop
      new_line;
      put_line("Choose one of the following :");
      put_line("  0. exit the program.");
      put_line("  1. standard integer numbers.");
      put_line("  2. standard complex numbers.");
      put_line("  3. multi-precision natural numbers.");
      put_line("  4. multi-precision integer numbers.");
      put_line("  5. multi-precision floating numbers.");
      put_line("  6. multi-precision complex numbers.");
      put("Make your choice (0,1,2,3,4,5 or 6) : "); get(ans);
      exit when (ans = '0');
      case ans is
        when '1' => Random_Standard_Integer;
        when '2' => Random_Standard_Complex;
        when '3' => Random_Multprec_Natural;
        when '4' => Random_Multprec_Integer;
        when '5' => Random_Multprec_Floating;
        when '6' => Random_Multprec_Complex;
        when others => null;
      end case;
    end loop;
  end Main;

begin
  Main;
end ts_random;