Commit 6812b99b by Paul Hilfinger Committed by Arnaud Charlet

impunit.adb: Re-organize System.Random_Numbers and GNAT.Random_Numbers and add to builds.

2007-08-14  Paul Hilfinger  <hilfinger@adacore.com>

	* impunit.adb: Re-organize System.Random_Numbers and
	GNAT.Random_Numbers and add to builds.

	* Makefile.rtl: Add s-rannum.ad* and g-rannum.ad*, a-assert*

	* s-rannum.ads, s-rannum.adb, g-rannum.ads, g-rannum.adb: New files.

	* a-assert.ads, a-assert.adb: New files.

From-SVN: r127454
parent f86eb278
......@@ -21,7 +21,7 @@
# This makefile fragment is included in the ada Makefile (both Unix
# and NT and VMS versions).
# It's purpose is to allow the separate maintainence of the list of
# Its purpose is to allow the separate maintainence of the list of
# GNATRTL objects, which frequently changes.
# Objects needed only for tasking
......@@ -76,6 +76,7 @@ GNATRTL_TASKING_OBJS= \
# Objects needed for non-tasking.
GNATRTL_NONTASKING_OBJS= \
a-assert$(objext) \
a-calari$(objext) \
a-caldel$(objext) \
a-calend$(objext) \
......@@ -158,6 +159,7 @@ GNATRTL_NONTASKING_OBJS= \
a-ngcefu$(objext) \
a-ngcoty$(objext) \
a-ngelfu$(objext) \
a-ngrear$(objext) \
a-nlcefu$(objext) \
a-nlcoty$(objext) \
a-nlelfu$(objext) \
......@@ -303,6 +305,7 @@ GNATRTL_NONTASKING_OBJS= \
a-zzunio$(objext) \
ada$(objext) \
calendar$(objext) \
directio$(objext) \
g-allein$(objext) \
g-alleve$(objext) \
g-altcon$(objext) \
......@@ -350,6 +353,7 @@ GNATRTL_NONTASKING_OBJS= \
g-moreex$(objext) \
g-os_lib$(objext) \
g-pehage$(objext) \
g-rannum$(objext) \
g-regexp$(objext) \
g-regpat$(objext) \
g-sestin$(objext) \
......@@ -523,6 +527,7 @@ GNATRTL_NONTASKING_OBJS= \
s-poosiz$(objext) \
s-powtab$(objext) \
s-purexc$(objext) \
s-rannum$(objext) \
s-regexp$(objext) \
s-regpat$(objext) \
s-restri$(objext) \
......@@ -584,5 +589,9 @@ GNATRTL_NONTASKING_OBJS= \
s-wwdcha$(objext) \
s-wwdenu$(objext) \
s-wwdwch$(objext) \
sequenio$(objext) \
system$(objext) \
text_io$(objext) $(EXTRA_GNATRTL_NONTASKING_OBJS)
text_io$(objext) \
unchconv$(objext) \
unchdeal$(objext) \
$(EXTRA_GNATRTL_NONTASKING_OBJS)
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- A D A . A S S E R T --
-- --
-- B o d y --
-- --
-- Copyright (C) 2007, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
package body Ada.Assertions is
------------
-- Assert --
------------
procedure Assert (Check : Boolean) is
begin
if Check = False then
raise Ada.Assertions.Assertion_Error;
end if;
end Assert;
procedure Assert (Check : Boolean; Message : String) is
begin
if Check = False then
raise Ada.Assertions.Assertion_Error with Message;
end if;
end Assert;
end Ada.Assertions;
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- A D A . A S S E R T --
-- --
-- S p e c --
-- --
-- This specification is derived from the Ada Reference Manual for use with --
-- GNAT. In accordance with the copyright of that document, you can freely --
-- copy and modify this specification, provided that if you redistribute a --
-- modified version, any changes that you have made are clearly indicated. --
-- --
------------------------------------------------------------------------------
-- We do a with of System.Assertions to get hold of the exception (following
-- the specific RM permission that lets' Assertion_Error being a renaming).
-- The suppression of Warnings stops the warning about bad categorization.
pragma Warnings (Off);
with System.Assertions;
pragma Warnings (On);
package Ada.Assertions is
pragma Pure (Assertions);
Assertion_Error : exception renames System.Assertions.Assert_Failure;
procedure Assert (Check : Boolean);
procedure Assert (Check : Boolean; Message : String);
end Ada.Assertions;
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- G N A T . R A N D O M _ N U M B E R S --
-- --
-- S p e c --
-- --
-- Copyright (C) 2007, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- Extended pseudo-random number generation
-- This package provides a type representing pseudo-random number
-- generators, and subprograms to extract various distributions of numbers
-- from them. It also provides types for representing initialization values
-- and snapshots of internal generator state, which permit reproducible
-- pseudo-random streams.
-- The generator currently provided by this package has an extremely long
-- period (at least 2**19937-1), and passes the Big Crush test suite, with
-- the exception of the two linear complexity tests. Therefore, it is
-- suitable for simulations, but should not be used as a cryptographic
-- pseudo-random source without additional processing.
-- The design of this package effects some simplification from that of
-- the standard Ada.Numerics packages. There is no separate State type;
-- the Generator type itself suffices for this purpose. The parameter
-- modes on Reset procedures better reflect the effect of these routines.
with System.Random_Numbers;
with Interfaces; use Interfaces;
package GNAT.Random_Numbers is
type Generator is limited private;
subtype Initialization_Vector is
System.Random_Numbers.Initialization_Vector;
function Random (Gen : Generator) return Float;
function Random (Gen : Generator) return Long_Float;
-- Return pseudo-random numbers uniformly distributed on [0 .. 1)
function Random (Gen : Generator) return Interfaces.Integer_32;
function Random (Gen : Generator) return Interfaces.Unsigned_32;
function Random (Gen : Generator) return Interfaces.Integer_64;
function Random (Gen : Generator) return Interfaces.Unsigned_64;
function Random (Gen : Generator) return Integer;
function Random (Gen : Generator) return Long_Integer;
-- Return pseudo-random numbers uniformly distributed on T'First .. T'Last
-- for various builtin integer types.
generic
type Result_Subtype is (<>);
Default_Min : Result_Subtype := Result_Subtype'Val (0);
function Random_Discrete
(Gen : Generator;
Min : Result_Subtype := Default_Min;
Max : Result_Subtype := Result_Subtype'Last) return Result_Subtype;
-- Returns pseudo-random numbers uniformly distributed on Min .. Max
generic
type Result_Subtype is digits <>;
function Random_Float (Gen : Generator) return Result_Subtype;
-- Returns pseudo-random numbers uniformly distributed on [0 .. 1)
function Random_Gaussian (Gen : Generator) return Long_Float;
function Random_Gaussian (Gen : Generator) return Float;
-- Returns pseudo-random numbers normally distributed value with mean 0
-- and standard deviation 1.0.
procedure Reset (Gen : out Generator);
-- Re-initialize the state of Gen from the time of day
procedure Reset
(Gen : out Generator;
Initiator : Initialization_Vector);
procedure Reset
(Gen : out Generator;
Initiator : Interfaces.Integer_32);
procedure Reset
(Gen : out Generator;
Initiator : Interfaces.Unsigned_32);
procedure Reset
(Gen : out Generator;
Initiator : Integer);
-- Re-initialize Gen based on the Initiator in various ways. Identical
-- values of Initiator cause identical sequences of values.
procedure Reset (Gen : out Generator; From_State : Generator);
-- Causes the state of Gen to be identical to that of From_State; Gen
-- and From_State will produce identical sequences of values subsequently.
procedure Reset (Gen : out Generator; From_Image : String);
function Image (Gen : Generator) return String;
-- The call
-- Reset (Gen2, Image (Gen1))
-- has the same effect as Reset (Gen2, Gen1);
Max_Image_Width : constant :=
System.Random_Numbers.Max_Image_Width + 2 + 20 + 5;
-- Maximum possible length of result of Image (...)
private
type Generator is limited record
Rep : System.Random_Numbers.Generator;
Have_Gaussian : Boolean;
-- The algorithm used for Random_Gaussian produces deviates in
-- pairs. Have_Gaussian is true iff Random_Gaussian has returned one
-- member of the pair and Next_Gaussian contains the other.
Next_Gaussian : Long_Float;
-- Next random deviate to be produced by Random_Gaussian, if
-- Have_Gaussian.
end record;
end GNAT.Random_Numbers;
......@@ -247,6 +247,7 @@ package body Impunit is
"g-moreex", -- GNAT.Most_Recent_Exception
"g-os_lib", -- GNAT.Os_Lib
"g-pehage", -- GNAT.Perfect_Hash_Generators
"g-rannum", -- GNAT.Random_Numbers
"g-regexp", -- GNAT.Regexp
"g-regist", -- GNAT.Registry
"g-regpat", -- GNAT.Regpat
......@@ -333,6 +334,7 @@ package body Impunit is
-- Ada Hierarchy Units from Ada 2005 Reference Manual --
--------------------------------------------------------
"a-assert", -- Ada.Assertions
"a-calari", -- Ada.Calendar.Arithmetic
"a-calfor", -- Ada.Calendar.Formatting
"a-catizo", -- Ada.Calendar.Time_Zones
......
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . R A N D O M _ N U M B E R S --
-- --
-- S p e c --
-- --
-- Copyright (C) 2007, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- Extended pseudo-random number generation
-- This package provides a type representing pseudo-random number generators,
-- and subprograms to extract various uniform distributions of numbers
-- from them. It also provides types for representing initialization values
-- and snapshots of internal generator state, which permit reproducible
-- pseudo-random streams.
-- The generator currently provided by this package has an extremely long
-- period (at least 2**19937-1), and passes the Big Crush test suite, with the
-- exception of the two linear complexity tests. Therefore, it is suitable
-- for simulations, but should not be used as a cryptographic pseudo-random
-- source without additional processing.
-- Note: this package is in the System hierarchy so that it can be directly
-- used by other predefined packages. User access to this package is via
-- the package GNAT.Random_Numbers (file g-rannum.ads), which also extends
-- its capabilities. The interfaces are different so as to include in
-- System.Random_Numbers only the definitions necessary to implement the
-- standard random-number packages Ada.Numerics.Float_Random and
-- Ada.Numerics.Discrete_Random.
with Interfaces;
package System.Random_Numbers is
type Generator is limited private;
type State is private;
-- A non-limited version of a Generator's internal state
function Random (Gen : Generator) return Float;
function Random (Gen : Generator) return Long_Float;
-- Return pseudo-random numbers uniformly distributed on [0 .. 1)
function Random (Gen : Generator) return Interfaces.Unsigned_32;
function Random (Gen : Generator) return Interfaces.Unsigned_64;
-- Return pseudo-random numbers uniformly distributed on T'First .. T'Last
-- for builtin integer types.
generic
type Result_Subtype is (<>);
Default_Min : Result_Subtype := Result_Subtype'Val (0);
function Random_Discrete
(Gen : Generator;
Min : Result_Subtype := Default_Min;
Max : Result_Subtype := Result_Subtype'Last) return Result_Subtype;
-- Returns pseudo-random numbers uniformly distributed on Min .. Max
generic
type Result_Subtype is digits <>;
function Random_Float (Gen : Generator) return Result_Subtype;
-- Returns pseudo-random numbers uniformly distributed on [0 .. 1)
type Initialization_Vector is
array (Integer range <>) of Interfaces.Unsigned_32;
-- Provides the most general initialization values for a generator (used
-- in Reset). In general, there is little point in providing more than
-- a certain number of values (currently 624).
procedure Reset (Gen : out Generator);
-- Re-initialize the state of Gen from the time of day
procedure Reset (Gen : out Generator; Initiator : Initialization_Vector);
procedure Reset (Gen : out Generator; Initiator : Interfaces.Integer_32);
procedure Reset (Gen : out Generator; Initiator : Interfaces.Unsigned_32);
procedure Reset (Gen : out Generator; Initiator : Integer);
-- Re-initialize Gen based on the Initiator in various ways. Identical
-- values of Initiator cause identical sequences of values.
procedure Reset (Gen : out Generator; From_State : Generator);
-- Causes the state of Gen to be identical to that of From_State; Gen
-- and From_State will produce identical sequences of values subsequently.
procedure Reset (Gen : out Generator; From_State : State);
procedure Save (Gen : Generator; To_State : out State);
-- The sequence
-- Save (Gen2, S); Reset (Gen1, S)
-- has the same effect as Reset (Gen2, Gen1).
procedure Reset (Gen : out Generator; From_Image : String);
function Image (Gen : Generator) return String;
-- The call
-- Reset (Gen2, Image (Gen1))
-- has the same effect as Reset (Gen2, Gen1);
Max_Image_Width : constant := 11 * 624;
-- Maximum possible length of result of Image (...)
function Image (Of_State : State) return String;
-- A String representation of Of_State. Identical to the result of
-- Image (Gen), if Of_State has been set with Save (Gen, Of_State).
function Value (Coded_State : String) return State;
-- Inverse of Image on States
private
N : constant := 624;
-- The number of 32-bit integers in the shift register
M : constant := 397;
-- Feedback distance from the current position
subtype State_Val is Interfaces.Unsigned_32;
type State is array (0 .. N - 1) of State_Val;
type Generator is limited record
S : State := (others => 0);
-- The shift register, a circular buffer
I : Integer := N;
-- Current starting position in shift register S
end record;
end System.Random_Numbers;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment