[BACK]Return to multprec_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/multprec_random_numbers.adb, Revision 1.1.1.1

1.1       maekawa     1: with Standard_Floating_Numbers;          use Standard_Floating_Numbers;
                      2: with Standard_Random_Numbers;
                      3:
                      4: package body Multprec_Random_Numbers is
                      5:
                      6:   function Random ( size : natural ) return Natural_Number is
                      7:
                      8:     res : Natural_Number;
                      9:     arn : Array_of_Naturals(0..size);
                     10:
                     11:   begin
                     12:     for i in arn'range loop
                     13:       arn(i) := Standard_Random_Numbers.Random(0,Base-1);
                     14:     end loop;
                     15:     res := Create(arn);
                     16:     return res;
                     17:   end Random;
                     18:
                     19:   function Random ( size : natural ) return Integer_Number is
                     20:
                     21:     res : Integer_Number;
                     22:     sig : double_float := Standard_Random_Numbers.Random;
                     23:     rnd : Natural_Number := Random(size);
                     24:
                     25:   begin
                     26:     res := Create(rnd);
                     27:     if sig < 0.0
                     28:      then Min(res);
                     29:     end if;
                     30:     Clear(rnd);
                     31:     return res;
                     32:   end Random;
                     33:
                     34:   function Random ( size : natural ) return Floating_Number is
                     35:
                     36:     res : Floating_Number;
                     37:     naturfrac : Natural_Number := Random(size);
                     38:     frac,expo : Integer_Number;
                     39:
                     40:   begin
                     41:     frac := Create(naturfrac);
                     42:     Clear(naturfrac);
                     43:     expo := Create(-Decimal_Places(frac));
                     44:     res := Create(frac,expo);
                     45:     Clear(frac); Clear(expo);
                     46:     return res;
                     47:   end Random;
                     48:
                     49:   function Random ( size : natural ) return Complex_Number is
                     50:
                     51:     res : Complex_Number;
                     52:     re : Floating_Number := Random(size);
                     53:     im : Floating_Number := Random(size);
                     54:
                     55:   begin
                     56:     res := Create(re,im);
                     57:     Clear(re); Clear(im);
                     58:     return res;
                     59:   end Random;
                     60:
                     61: end Multprec_Random_Numbers;

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