-
+ B2F65C66488B4070367DE205D1AB29EB50633B6A7B81611FA07492188FC255047C51A6ECAE15E8BC4F18C934812FD88FDA073E67DD4D92E0C810B6FEA282FC0C
udp/libmt/mt.ads
(0 . 0)(1 . 47)
142 -- Ada implementation of the Mersenne Twister Pseudo-Random number generator
143 -- S.MG, 2018
144
145 with Interfaces; use Interfaces;
146
147 package MT is
148 -- Interfaces.Unsigned_32 in GNAT is mod 2**32 and has bitwise shifts defined
149 subtype U32 is Interfaces.Unsigned_32;
150
151 -- period parameters
152 N : constant := 624;
153 M : constant := 397;
154 MATRIX_MASK: constant U32 := 16#9908_b0df#;
155 UPPER_MASK : constant U32 := 16#8000_0000#;
156 LOWER_MASK : constant U32 := 16#7fff_ffff#;
157
158 -- array type for storing the state vector of the generator
159 type State_Type is Array( 0 .. N-1 ) of U32;
160
161 -- array type for initialization by array - change key len here if needed
162 KEY_LEN : constant := 4;
163 type Init_Array_Type is Array( 0 .. KEY_LEN - 1 ) of U32;
164
165 -- exception raised by a call to generator before initializing it
166 No_Init_Exception : exception;
167
168 -- initialize the generator with a seed (number)
169 procedure Init_Genrand(Seed : in U32);
170
171 -- initialize the generator with array of 8-octets elements
172 procedure Init_Genrand(Seed : in Init_Array_Type);
173
174 -- generate the next pseudo-random 32 bits number in the sequence
175 function Gen_U32 return U32;
176
177 -- for testing
178 function Get_State return State_Type;
179
180 -- internals of the generator, NOT for direct access
181 private
182 -- actual state of the generator
183 State : State_Type;
184
185 -- flag for generator routine
186 Mti_Flag : U32 := N + 1; -- default value -> state(N) is not initialised
187
188 end MT;