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

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

Revision 1.1.1.1 (vendor branch), Sun Oct 29 17:45:26 2000 UTC (23 years, 8 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 Machines;                           use Machines;
with Standard_Mathematical_Functions;    use Standard_Mathematical_Functions;

package body Standard_Random_Numbers is

  a : constant integer := 13849;
  m : constant integer := 65536;
  c : constant integer := 56963;
  seed : integer := Process_Id;

  function Random ( lower,upper : integer ) return integer is

    f : double_float;

  begin
    f := Random; -- f in [-1,1]
    f := 0.5*(double_float(upper-lower)*f + double_float(lower+upper));
                                         -- f in [lower,upper]
    return integer(f); -- rounding the result to integer number
  end Random;

  function Random return double_float is

    x : double_float;

  begin
    seed := (a*seed + c) mod m;
    x := double_float(seed)/double_float(m);
    x := 2.0 * x - 1.0;
    return x;
  end Random;
  
  function Random return Complex_Number is
  begin
    return Create(Random,Random);
  end Random;

  function Random ( modulus : double_float ) return Complex_Number is

    arg : double_float;

  begin
    arg := PI*Random;  -- in [-pi,+pi]
    return Create(modulus*COS(arg),modulus*SIN(arg));
  end Random;

  function Random1 return Complex_Number is

    arg : double_float; 

  begin
    arg := PI*Random;  -- in [-pi,+pi]
    return Create(COS(arg),SIN(arg));
  end Random1;

end Standard_Random_Numbers;