raw
mt_prng                 1  -- Ada implementation of the Mersenne Twister Pseudo-Random number generator
mt_prng 2 -- S.MG, 2018
mt_prng 3
mt_prng 4 with Interfaces; use Interfaces;
mt_prng 5
mt_prng 6 package MT is
mt_prng 7 -- Interfaces.Unsigned_32 in GNAT is mod 2**32 and has bitwise shifts defined
mt_prng 8 subtype U32 is Interfaces.Unsigned_32;
mt_prng 9
mt_prng 10 -- period parameters
mt_prng 11 N : constant := 624;
mt_prng 12 M : constant := 397;
mt_prng 13 MATRIX_MASK: constant U32 := 16#9908_b0df#;
mt_prng 14 UPPER_MASK : constant U32 := 16#8000_0000#;
mt_prng 15 LOWER_MASK : constant U32 := 16#7fff_ffff#;
mt_prng 16
mt_prng 17 -- array type for storing the state vector of the generator
mt_prng 18 type State_Type is Array( 0 .. N-1 ) of U32;
mt_prng 19
mt_prng 20 -- array type for initialization by array - change key len here if needed
mt_prng 21 KEY_LEN : constant := 4;
mt_prng 22 type Init_Array_Type is Array( 0 .. KEY_LEN - 1 ) of U32;
mt_prng 23
mt_prng 24 -- exception raised by a call to generator before initializing it
mt_prng 25 No_Init_Exception : exception;
mt_prng 26
mt_prng 27 -- initialize the generator with a seed (number)
mt_prng 28 procedure Init_Genrand(Seed : in U32);
mt_prng 29
mt_prng 30 -- initialize the generator with array of 8-octets elements
mt_prng 31 procedure Init_Genrand(Seed : in Init_Array_Type);
mt_prng 32
mt_prng 33 -- generate the next pseudo-random 32 bits number in the sequence
mt_prng 34 function Gen_U32 return U32;
mt_prng 35
mt_prng 36 -- for testing
mt_prng 37 function Get_State return State_Type;
mt_prng 38
mt_prng 39 -- internals of the generator, NOT for direct access
mt_prng 40 private
mt_prng 41 -- actual state of the generator
mt_prng 42 State : State_Type;
mt_prng 43
mt_prng 44 -- flag for generator routine
mt_prng 45 Mti_Flag : U32 := N + 1; -- default value -> state(N) is not initialised
mt_prng 46
mt_prng 47 end MT;