-- Ada implementation of the Mersenne Twister Pseudo-Random number generator -- S.MG, 2018 with Interfaces; use Interfaces; package MT is -- Interfaces.Unsigned_32 in GNAT is mod 2**32 and has bitwise shifts defined subtype U32 is Interfaces.Unsigned_32; -- period parameters N : constant := 624; M : constant := 397; MATRIX_MASK: constant U32 := 16#9908_b0df#; UPPER_MASK : constant U32 := 16#8000_0000#; LOWER_MASK : constant U32 := 16#7fff_ffff#; -- array type for storing the state vector of the generator type State_Type is Array( 0 .. N-1 ) of U32; -- array type for initialization by array - change key len here if needed KEY_LEN : constant := 4; type Init_Array_Type is Array( 0 .. KEY_LEN - 1 ) of U32; -- exception raised by a call to generator before initializing it No_Init_Exception : exception; -- initialize the generator with a seed (number) procedure Init_Genrand(Seed : in U32); -- initialize the generator with array of 8-octets elements procedure Init_Genrand(Seed : in Init_Array_Type); -- generate the next pseudo-random 32 bits number in the sequence function Gen_U32 return U32; -- for testing function Get_State return State_Type; -- internals of the generator, NOT for direct access private -- actual state of the generator State : State_Type; -- flag for generator routine Mti_Flag : U32 := N + 1; -- default value -> state(N) is not initialised end MT;