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

Annotation of OpenXM_contrib/PHC/Ada/Math_Lib/Numbers/standard_random_numbers.adb, Revision 1.1.1.1

1.1       maekawa     1: with Machines;                           use Machines;
                      2: with Standard_Mathematical_Functions;    use Standard_Mathematical_Functions;
                      3:
                      4: package body Standard_Random_Numbers is
                      5:
                      6:   a : constant integer := 13849;
                      7:   m : constant integer := 65536;
                      8:   c : constant integer := 56963;
                      9:   seed : integer := Process_Id;
                     10:
                     11:   function Random ( lower,upper : integer ) return integer is
                     12:
                     13:     f : double_float;
                     14:
                     15:   begin
                     16:     f := Random; -- f in [-1,1]
                     17:     f := 0.5*(double_float(upper-lower)*f + double_float(lower+upper));
                     18:                                          -- f in [lower,upper]
                     19:     return integer(f); -- rounding the result to integer number
                     20:   end Random;
                     21:
                     22:   function Random return double_float is
                     23:
                     24:     x : double_float;
                     25:
                     26:   begin
                     27:     seed := (a*seed + c) mod m;
                     28:     x := double_float(seed)/double_float(m);
                     29:     x := 2.0 * x - 1.0;
                     30:     return x;
                     31:   end Random;
                     32:
                     33:   function Random return Complex_Number is
                     34:   begin
                     35:     return Create(Random,Random);
                     36:   end Random;
                     37:
                     38:   function Random ( modulus : double_float ) return Complex_Number is
                     39:
                     40:     arg : double_float;
                     41:
                     42:   begin
                     43:     arg := PI*Random;  -- in [-pi,+pi]
                     44:     return Create(modulus*COS(arg),modulus*SIN(arg));
                     45:   end Random;
                     46:
                     47:   function Random1 return Complex_Number is
                     48:
                     49:     arg : double_float;
                     50:
                     51:   begin
                     52:     arg := PI*Random;  -- in [-pi,+pi]
                     53:     return Create(COS(arg),SIN(arg));
                     54:   end Random1;
                     55:
                     56: end Standard_Random_Numbers;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>