aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/a-nudira.ads
diff options
context:
space:
mode:
authorPaul Hilfinger <hilfinger@adacore.com>2010-06-22 15:24:10 +0000
committerArnaud Charlet <charlet@gcc.gnu.org>2010-06-22 17:24:10 +0200
commit41195c94583a5f2da9178234bbcdacee27db69ff (patch)
tree7ad4f5d9484bab54aefb464310bc5032a6f6961c /gcc/ada/a-nudira.ads
parent07309d58d08122d67d722bc297eb371d9788488c (diff)
downloadgcc-41195c94583a5f2da9178234bbcdacee27db69ff.zip
gcc-41195c94583a5f2da9178234bbcdacee27db69ff.tar.gz
gcc-41195c94583a5f2da9178234bbcdacee27db69ff.tar.bz2
2010-06-22 Paul Hilfinger <hilfinger@adacore.com>
* a-nudira.adb, a-nudira.ads, a-nuflra.adb, a-nuflra.ads, gnat_rm.texi, impunit.adb, Makefile.rtl, s-rannum.adb (Random_Float_Template, Random): New method of creating uniform floating-point variables that allow the creation of all machine values in [0 .. 1). * g-mbdira.adb, g-mbflra.adb, g-mbdira.ads, g-mbflra.ads: New file. From-SVN: r161191
Diffstat (limited to 'gcc/ada/a-nudira.ads')
-rw-r--r--gcc/ada/a-nudira.ads57
1 files changed, 9 insertions, 48 deletions
diff --git a/gcc/ada/a-nudira.ads b/gcc/ada/a-nudira.ads
index 425aa6f..03ce48b 100644
--- a/gcc/ada/a-nudira.ads
+++ b/gcc/ada/a-nudira.ads
@@ -6,7 +6,7 @@
-- --
-- S p e c --
-- --
--- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
+-- Copyright (C) 1992-2010, Free Software Foundation, Inc. --
-- --
-- This specification is derived from the Ada Reference Manual for use with --
-- GNAT. The copyright notice above, and the license provisions that follow --
@@ -33,39 +33,24 @@
-- --
------------------------------------------------------------------------------
--- Note: the implementation used in this package was contributed by Robert
--- Eachus. It is based on the work of L. Blum, M. Blum, and M. Shub, SIAM
--- Journal of Computing, Vol 15. No 2, May 1986. The particular choices for P
--- and Q chosen here guarantee a period of 562,085,314,430,582 (about 2**49),
--- and the generated sequence has excellent randomness properties. For further
--- details, see the paper "Fast Generation of Trustworthy Random Numbers", by
--- Robert Eachus, which describes both the algorithm and the efficient
--- implementation approach used here.
+-- Note: the implementation used in this package is a version of the
+-- Mersenne Twister. See s-rannum.adb for details and references.
-with Interfaces;
+with System.Random_Numbers;
generic
type Result_Subtype is (<>);
package Ada.Numerics.Discrete_Random is
- -- The algorithm used here is reliable from a required statistical point of
- -- view only up to 48 bits. We try to behave reasonably in the case of
- -- larger types, but we can't guarantee the required properties. So
- -- generate a warning for these (slightly) dubious cases.
-
- pragma Compile_Time_Warning
- (Result_Subtype'Size > 48,
- "statistical properties not guaranteed for size > 48");
-
-- Basic facilities
type Generator is limited private;
function Random (Gen : Generator) return Result_Subtype;
- procedure Reset (Gen : Generator);
procedure Reset (Gen : Generator; Initiator : Integer);
+ procedure Reset (Gen : Generator);
-- Advanced facilities
@@ -74,41 +59,17 @@ package Ada.Numerics.Discrete_Random is
procedure Save (Gen : Generator; To_State : out State);
procedure Reset (Gen : Generator; From_State : State);
- Max_Image_Width : constant := 80;
+ Max_Image_Width : constant := System.Random_Numbers.Max_Image_Width;
function Image (Of_State : State) return String;
function Value (Coded_State : String) return State;
private
- subtype Int is Interfaces.Integer_32;
- subtype Rst is Result_Subtype;
-
- -- We prefer to use 14 digits for Flt, but some targets are more limited
-
- type Flt is digits Positive'Min (14, Long_Long_Float'Digits);
-
- RstF : constant Flt := Flt (Rst'Pos (Rst'First));
- RstL : constant Flt := Flt (Rst'Pos (Rst'Last));
-
- Offs : constant Flt := RstF - 0.5;
-
- K1 : constant := 94_833_359;
- K1F : constant := 94_833_359.0;
- K2 : constant := 47_416_679;
- K2F : constant := 47_416_679.0;
- Scal : constant Flt := (RstL - RstF + 1.0) / (K1F * K2F);
-
- type State is record
- X1 : Int := Int (2999 ** 2);
- X2 : Int := Int (1439 ** 2);
- P : Int := K1;
- Q : Int := K2;
- FP : Flt := K1F;
- Scl : Flt := Scal;
- end record;
type Generator is limited record
- Gen_State : State;
+ Rep : System.Random_Numbers.Generator;
end record;
+ type State is new System.Random_Numbers.State;
+
end Ada.Numerics.Discrete_Random;