DEVELOPMENT EDITION · 769442725406
Library Reference
On this page

Package Ada.Numerics.Float_Random

Ada.Numerics.Float_Random (RM A.5.2): uniformly distributed floats 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 Uniformly_Distributed. 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.

Generator

type Generator is limited private;

Uniformly_Distributed

subtype Uniformly_Distributed is Float range 0.0 .. 1.0;

Random

function Random (Gen : in out Generator) return Uniformly_Distributed
  with Side_Effects, Global => null;

the next value, a multiple of 2 ** (-24) from 0.0 up to 1.0 (exclusive)

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)