Generic package Ada.Numerics.Discrete_Random
Ada.Numerics.Discrete_Random (RM A.5.2): uniformly distributed values of a discrete subtype from a generator the program declares and passes. A generator's state is an object of its own, changed by each call (Random is a function with side effects on Gen), so no state is hidden from the proof; a result is known only to lie in its range. The generator is xoshiro256** (Blackman and Vigna, 2018), seeded through SplitMix64: a state of four 64-bit words, period 2 ** 256 - 1. It is not for cryptography.
generic
type Result_Subtype is (<>);Generator
type Generator is limited private;Random
function Random (Gen : in out Generator) return Result_Subtype
with Side_Effects, Global => null,
Pre => Result_Subtype'First <= Result_Subtype'Last;the next value: the next 64-bit word modulo the subtype's number of values (so each value comes with a probability within Count / 2 ** 64 of 1 / Count)
Random
function Random (Gen : in out Generator; First, Last : Result_Subtype) return Result_Subtype
with Side_Effects, Global => null,
Pre => First <= Last,
Post => Random'Result in First .. Last;the next value from First .. Last, likewise
Reset
procedure Reset (Gen : in out Generator; Initiator : Integer)
with Global => null;the state the initiator chooses: the same initiator gives the same values
Reset
procedure Reset (Gen : in out Generator)
with Global => null;a state chosen by the time (the monotonic clock's nanoseconds)
State
type State is private;Save
procedure Save (Gen : Generator; To_State : out State)
with Global => null;the generator's state, to Reset it to later
Reset
procedure Reset (Gen : in out Generator; From_State : State)
with Global => null;the state a Save gave
Max_Image_Width
Max_Image_Width : constant := 64;a state's image: its four words in hexadecimal, 16 digits each
Is_Image
function Is_Image (Coded_State : String) return Boolean is
(Coded_State'Length = Max_Image_Width
and then (for all C of Coded_State => C in '0' .. '9' | 'A' .. 'F' | 'a' .. 'f'));(Verada) whether a string is the image of a state: Max_Image_Width hexadecimal digits, of either case
Image
function Image (Of_State : State) return String
with Global => null,
Post => Image'Result'First = 1 and then Is_Image (Image'Result);Value
function Value (Coded_State : String) return State
with Global => null,
Pre => Is_Image (Coded_State);the state an image names (where the RM raises Constraint_Error, the precondition requires an image; the image of no state, all zeros, gives Reset (Gen, 0)'s state)