DEVELOPMENT EDITION · 769442725406
Library Reference
On this page

Ada.Numerics.Float_Random

Uniformly distributed floats from a generator the program declares and passes (RM A.5.2).

Read the family guide for representation, selection and resource rules. The complete declaration page retains exact signatures/contracts; the source specification is the implementation baseline.

Availability and ownership

The generator is xoshiro256** seeded through SplitMix64; Random is a function with side effects on its in out generator, so it is called only as the whole value of an assignment or declaration. A result is known only to lie in Uniformly_Distributed. Its bodies are proved (test/programs/prove/library-ada-numerics-random).

A client proof uses these contracts without proving the body again (see library assurance). Global => null excludes package-global effects, not changes made through an in out argument.

Import and instantiate

with Ada.Numerics.Float_Random;
import Ada.Numerics.Float_Random;

A Vibe module imports this unit's names with from Ada.Numerics.Float_Random import Name; see library use across syntaxes. In Varc, keep each name's declared spelling and write & on arguments the call changes.

Contract and lifecycle reading

A Pre condition is the caller's obligation; a Post is what a normal return guarantees. What a postcondition does not state, a client cannot assume. Ghost functions are for contracts and ghost code. The family guide describes copying, lifetime, order and cost.

API 001

Generator (declaration) — 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.

Declared interface:

type Generator is limited private;

API 002

Uniformly_Distributed (declaration) — 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.

Declared interface:

subtype Uniformly_Distributed is Float range 0.0 .. 1.0;

API 003

Random (declaration) — The next value, a multiple of 2 ** (-24) from 0.0 up to 1.0 (exclusive)

Declared interface:

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

API 004

Reset (declaration) — The state the initiator chooses: the same initiator gives the same values.

Declared interface:

procedure Reset (Gen : in out Generator; Initiator : Integer)
  with Global => null;

API 005

Reset (declaration) — A state chosen by the time (the monotonic clock's nanoseconds)

Declared interface:

procedure Reset (Gen : in out Generator)
  with Global => null;

API 006

State (declaration) — A state chosen by the time (the monotonic clock's nanoseconds)

Declared interface:

type State is private;

API 007

Save (declaration) — A state chosen by the time (the monotonic clock's nanoseconds)

Declared interface:

procedure Save (Gen : Generator; To_State : out State)
  with Global => null;

API 008

Reset (declaration) — A state chosen by the time (the monotonic clock's nanoseconds)

Declared interface:

procedure Reset (Gen : in out Generator; From_State : State)
  with Global => null;

API 009

Max_Image_Width (declaration) — A state's image: its four words in hexadecimal, 16 digits each.

Declared interface:

Max_Image_Width : constant := 64;

API 010

Is_Image (declaration) — (Verada) whether a string is the image of a state: Max_Image_Width hexadecimal digits, of either case.

Declared interface:

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'));

API 011

Image (declaration) — (Verada) whether a string is the image of a state: Max_Image_Width hexadecimal digits, of either case.

Declared interface:

function Image (Of_State : State) return String
  with Global => null,
       Post => Image'Result'First = 1 and then Is_Image (Image'Result);

API 012

Value (declaration) — 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)

Declared interface:

function Value (Coded_State : String) return State
  with Global => null,
       Pre => Is_Image (Coded_State);