diff -uNr a/mt_generic_pkg/lib/README b/mt_generic_pkg/lib/README --- a/mt_generic_pkg/lib/README false +++ b/mt_generic_pkg/lib/README d0a1425d243ca61b62bf2d184348d3c314b43ed8ae83cd03ff466b3a1d7bb9d04bb5172f4c4d6368a354c04213e3fd5bfe826437db1b5b8c0fa6b633303e27b4 @@ -0,0 +1 @@ +lib diff -uNr a/mt_generic_pkg/manifest b/mt_generic_pkg/manifest --- a/mt_generic_pkg/manifest false +++ b/mt_generic_pkg/manifest cf7b913622918593e905ebc2064b1f3f4faabf82f3d9887685616503e42b68537082186b03bc164045de70a76d0b69d26d5bd0668f12253d4e376415c65c64bc @@ -0,0 +1 @@ +660482 mt_generic_genesis diana_coman The Mersenne Twister pseudo-random number generator implemented as a generic Ada package in a lib with tests against known values from the reference C implementation. diff -uNr a/mt_generic_pkg/mt.adb b/mt_generic_pkg/mt.adb --- a/mt_generic_pkg/mt.adb false +++ b/mt_generic_pkg/mt.adb b52b53fb67992eee6d9f456bfedcf24e944fa00dc66850c857d6d6b6d46ab115cab0d42f4693ce092d41e5cfbe6360932abe06b9b2244d3d902b52551076d503 @@ -0,0 +1,105 @@ + -- Ada implementation of the Mersenne Twister Pseudo-Random number generator + -- S.MG, 2020 + +package body MT is + -- to re-init this generator (with the SAME seed) + procedure Reset is + begin + Init_Genrand(Seed); + end Reset; + + -- generate the next pseudo-random 32 bits number in the sequence + function Gen_U32 return Interfaces.Unsigned_32 is + Y : Interfaces.Unsigned_32; + MASK1 : constant Interfaces.Unsigned_32 := Interfaces.Unsigned_32(1); + Mag01 : Array ( 0 .. 1 ) of Interfaces.Unsigned_32; + begin + -- Mag01[x] is x * Matrix_A of the algorithm for x 0 or 1 + Mag01(0) := Interfaces.Unsigned_32(0); + Mag01(1) := MATRIX_MASK; + + -- if no numbers available, generate another set of N words + if Mti_Flag >= N then + + -- this should NEVER happen as the init is called at instantiation + if Mti_Flag = (N + 1) then + -- Generator was NOT initialised! + -- Original C code initialises with default seed 5489 + -- This code will simply raise exception and abort + raise No_Init_Exception; + end if; + + for K in 0 .. N - M - 1 loop + Y := ( State(K) and UPPER_MASK ) or + ( State(K+1) and LOWER_MASK ); + State(K) := State(K+M) xor + Shift_Right(Y, 1) xor + Mag01(Integer(Y and MASK1)); + end loop; + for K in N-M .. N - 2 loop + Y := ( State(K) and UPPER_MASK ) or + ( State(K+1) and LOWER_MASK); + State(K) := State(K + M - N) xor + Shift_Right(Y, 1) xor + Mag01(Integer(Y and MASK1)); + end loop; + Y := (State(N-1) and UPPER_MASK ) or + (State(0) and LOWER_MASK ); + State(N - 1) := State(M-1) xor + Shift_Right(Y, 1) xor + Mag01(Integer(Y and MASK1)); + Mti_Flag := 0; + end if; + + -- retrieve next available number + Y := State(Integer(Mti_Flag)); + Mti_Flag := Mti_Flag + 1; + + -- tempering + Y := Y xor Shift_Right(Y, 11); + Y := Y xor (Shift_Left(Y, 7) and 16#9d2c_5680#); + Y := Y xor (Shift_Left(Y, 15) and 16#efc6_0000#); + Y := Y xor Shift_Right(Y, 18); + + -- return tempered number + return Y; + end Gen_U32; + + -- generate the next pseudo-random Float number in the interval a,b + function Gen_Float(a: in Float := 0.0; + b: in Float := 1.0) + return Float is + FU32: Float := Float(Gen_U32); + FMax: Float := Float(16#FFFFFFFF#); + begin + if b >= a then + return a + (FU32 / FMax) * (b - a); + else + return b + (FU32 / FMax) * (a - b); + end if; + end Gen_Float; + + -- to re-init this generator (with the SAME seed) + procedure Reset_Generator is + begin + Init_Genrand(Seed); + end Reset_Generator; + +-- private stuff + + procedure Init_Genrand(S : in Interfaces.Unsigned_32) is + begin + State(0) := S; + for I in State'First + 1 .. State'Last loop + State(I) := Interfaces.Unsigned_32(1812433253) * + ( State(I - 1) xor + ( Shift_Right(State(I - 1), 30) ) + ) + Interfaces.Unsigned_32(I) ; + end loop; + Mti_Flag := N; + end Init_Genrand; + +begin + -- initialize the prng with the Seed given at instantiation + Init_Genrand(Seed); +end MT; diff -uNr a/mt_generic_pkg/mt.ads b/mt_generic_pkg/mt.ads --- a/mt_generic_pkg/mt.ads false +++ b/mt_generic_pkg/mt.ads e5e3f1b8f54d19eddf351bac02eb42abfb4e9a78048ac4ab8fb72391b893a4453a80790f575b2f7a8d87b4f8b4a5af68fed272e4d44fc4a79e1f02b7581f92f2 @@ -0,0 +1,53 @@ + -- Ada implementation of the Mersenne Twister Pseudo-Random number generator + -- This is a generic package with Seed as param: + -- it's therefore ALWAYS seeded + -- it can be instantiated safely from multi-threaded environments + -- This has no init by array and/or change of seed. + -- S.MG, 2020 + +with Interfaces; use Interfaces; + +generic + Seed : in Interfaces.Unsigned_32; + +package MT is + -- this is NOT Pure (MT prng has an internal state) + -- but it needs elaborate_body to ensure MT is initialized with given seed + pragma Elaborate_Body; + + No_Init_Exception: exception; + + -- generate the next pseudo-random 32 bits number in the sequence + function Gen_U32 return Interfaces.Unsigned_32; + + -- generate the next pseudo-random Float number in the interval a,b + function Gen_Float(a: in Float := 0.0; + b: in Float := 1.0) + return Float; + + -- to re-init this generator (with the SAME seed) + procedure Reset_Generator; + + -- internals of the generator, NOT for direct access +private + -- initialize the generator with a seed (number) + procedure Init_Genrand(S : in Interfaces.Unsigned_32); + + -- period parameters + N : constant := 624; + M : constant := 397; + MATRIX_MASK: constant Interfaces.Unsigned_32 := 16#9908_b0df#; + UPPER_MASK : constant Interfaces.Unsigned_32 := 16#8000_0000#; + LOWER_MASK : constant Interfaces.Unsigned_32 := 16#7fff_ffff#; + + -- array type for storing the state vector of the generator + type State_Type is Array( 0 .. N-1 ) of Interfaces.Unsigned_32; + + -- actual state of the generator + State : State_Type; + + -- flag for generator routine + -- default value -> state(N) is not initialised + Mti_Flag : Interfaces.Unsigned_32 := N + 1; + +end MT; diff -uNr a/mt_generic_pkg/mt.gpr b/mt_generic_pkg/mt.gpr --- a/mt_generic_pkg/mt.gpr false +++ b/mt_generic_pkg/mt.gpr 541d85e5903e47101e277aeb34394b3fbb96d3c628dfacbeacfd920878cff7b1521afd9adb0072a216a71470e2a8664fe68685af42c0d5665063ca991e5504e5 @@ -0,0 +1,53 @@ + -- Ada implementation of the Mersenne Twister Pseudo-Random number generator + -- this provides a GENERIC package with SEED as parameter + -- S.MG, 2020 + -- + -- Implementing the algorithm as described by Matsumoto, M. and Nishimura, T.: + -- www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html + -- M.M and N.T, "Mersenne Twister: A 623-dimensionally equidistributed uniform + -- pseudorandom number generator", ACM Transactions on Modeling and Computer + -- Simulations: Special Issue on Uniform Random Number Generation, 1998. + +project MT is + for Object_Dir use "obj"; + + type Mode_Type is ("debug", "release"); + Mode : Mode_Type := external ("mode", "release"); + + for Languages use ("Ada"); + for Source_Dirs use ("."); + for Library_Dir use "lib"; + for Library_Name use "MT_GENERIC"; + for Library_Kind use "static"; + + package Compiler is + + case Mode is + when "debug" => + for Switches ("Ada") + use ("-g"); + when "release" => + for Switches ("Ada") + use ("-O2", "-fdump-scos", "-gnata", "-fstack-check", + "-gnatyd", "-gnatym", + "-fdata-sections", "-ffunction-sections", "-gnatwr", "-gnatw.d", + "-gnatec=" & MT'Project_Dir & "restrict.adc"); + end case; + end Compiler; + + package Builder is + for Switches ("Ada") + use ("-nostdlib"); + end Builder; + + package Binder is + case Mode is + when "debug" => + for Switches ("Ada") + use (); + when "release" => + for Switches ("Ada") + use ("-static"); + end case; + end Binder; +end MT; diff -uNr a/mt_generic_pkg/obj/README b/mt_generic_pkg/obj/README --- a/mt_generic_pkg/obj/README false +++ b/mt_generic_pkg/obj/README 50f9b127e6ae2019779520d8998bea7f559496b1847c7c66b6ce6a6f3fc20db67d45f1fbf7a9318c86ebba0694db73de168f409d8328a751f3104c1474a83a0d @@ -0,0 +1 @@ +obj diff -uNr a/mt_generic_pkg/restrict.adc b/mt_generic_pkg/restrict.adc --- a/mt_generic_pkg/restrict.adc false +++ b/mt_generic_pkg/restrict.adc a2a8048f3ebb3914b1c693be050881bdd135031a4990d270434579d3821572e10ecf059dbb70f83102c8d4758b308ac09a8873b64e8c5722f71def1582785e5d @@ -0,0 +1,63 @@ +pragma Restrictions(Immediate_Reclamation); +pragma Restrictions(Max_Asynchronous_Select_Nesting => 0); +pragma Restrictions(Max_Protected_Entries => 0); +pragma Restrictions(Max_Select_Alternatives => 0); +--pragma Restrictions(Max_Task_Entries => 0); +--pragma Restrictions(Max_Tasks => 0); +pragma Restrictions(No_Abort_Statements); +pragma Restrictions(No_Access_Parameter_Allocators); +pragma Restrictions(No_Allocators); +pragma Restrictions(No_Asynchronous_Control); +--pragma Restrictions(No_Calendar); +pragma Restrictions(No_Coextensions); +pragma Restrictions(No_Default_Stream_Attributes); +--pragma Restrictions(No_Delay); +pragma Restrictions(No_Dispatch); +pragma Restrictions(No_Dispatching_Calls); +pragma Restrictions(No_Dynamic_Attachment); +pragma Restrictions(No_Dynamic_Priorities); +pragma Restrictions(No_Entry_Calls_In_Elaboration_Code); +pragma Restrictions(No_Entry_Queue); +pragma Restrictions(No_Enumeration_Maps); +pragma Restrictions(No_Exception_Propagation); +pragma Restrictions(No_Exception_Registration); +pragma Restrictions(No_Finalization); +pragma Restrictions(No_Fixed_Io); +--pragma Restrictions(No_Floating_Point); +pragma Restrictions(No_Implementation_Aspect_Specifications); +pragma Restrictions(No_Implementation_Units); +pragma Restrictions(No_Implicit_Dynamic_Code); +pragma Restrictions(No_Implicit_Heap_Allocations); +pragma Restrictions(No_Implicit_Protected_Object_Allocations); +pragma Restrictions(No_Implicit_Task_Allocations); +pragma Restrictions(No_Initialize_Scalars); +pragma Restrictions(No_Local_Protected_Objects); +pragma Restrictions(No_Local_Timing_Events); +pragma Restrictions(No_Multiple_Elaboration); +pragma Restrictions(No_Nested_Finalization); +pragma Restrictions(No_Protected_Type_Allocators); +pragma Restrictions(No_Protected_Types); +--pragma Restrictions(No_Relative_Delay); +pragma Restrictions(No_Requeue_Statements); +pragma Restrictions(No_Secondary_Stack); +pragma Restrictions(No_Select_Statements); +pragma Restrictions(No_Specific_Termination_Handlers); +pragma Restrictions(No_Standard_Allocators_After_Elaboration); +pragma Restrictions(No_Stream_Optimizations); +pragma Restrictions(No_Streams); +pragma Restrictions(No_Task_Allocators); +pragma Restrictions(No_Task_At_Interrupt_Priority); +pragma Restrictions(No_Task_Attributes_Package); +--pragma Restrictions(No_Task_Hierarchy); +--pragma Restrictions(No_Tasking); +pragma Restrictions(No_Task_Termination); +pragma Restrictions(No_Terminate_Alternatives); +pragma Restrictions(No_Unchecked_Access); +pragma Restrictions(No_Unchecked_Conversion); +pragma Restrictions(No_Unchecked_Deallocation); +pragma Restrictions(No_Wide_Characters); +pragma Restrictions(Pure_Barriers); +pragma Restrictions(Simple_Barriers); +pragma Restrictions(Static_Priorities); +pragma Restrictions(Static_Storage_Size); +pragma Validity_Checks(ALL_CHECKS); diff -uNr a/mt_generic_pkg/testmt/obj/README b/mt_generic_pkg/testmt/obj/README --- a/mt_generic_pkg/testmt/obj/README false +++ b/mt_generic_pkg/testmt/obj/README 50f9b127e6ae2019779520d8998bea7f559496b1847c7c66b6ce6a6f3fc20db67d45f1fbf7a9318c86ebba0694db73de168f409d8328a751f3104c1474a83a0d @@ -0,0 +1 @@ +obj diff -uNr a/mt_generic_pkg/testmt/tests_mt.adb b/mt_generic_pkg/testmt/tests_mt.adb --- a/mt_generic_pkg/testmt/tests_mt.adb false +++ b/mt_generic_pkg/testmt/tests_mt.adb 0c7172556a4a40dfdc5f80306e0efc501e333c0d499e0481072fee1ac711185f04fde3a5ec17079a58e550c87c4047d8e3b52faea8701c5d73c05b25a31afaf8 @@ -0,0 +1,243 @@ + --S.MG, 2018 + +with Ada.Text_IO; use Ada.Text_IO; +with Interfaces; use Interfaces; +with MT; + +procedure Tests_MT is + Seed_Default : constant Interfaces.Unsigned_32 := 5489; + -- MT with Seed + package MTS is new MT( Seed => Seed_Default); use MTS; + -- variables and constants for test + X : Interfaces.Unsigned_32; + No : constant Integer := 1000; + -- values from reference C implementation with default seed 5489 + Result: Array(0..No-1) of Interfaces.Unsigned_32 := ( + 3499211612, 581869302, 3890346734, 3586334585, 545404204, + 4161255391, 3922919429, 949333985, 2715962298, 1323567403, + 418932835, 2350294565, 1196140740, 809094426, 2348838239, + 4264392720, 4112460519, 4279768804, 4144164697, 4156218106, + 676943009, 3117454609, 4168664243, 4213834039, 4111000746, + 471852626, 2084672536, 3427838553, 3437178460, 1275731771, + 609397212, 20544909, 1811450929, 483031418, 3933054126, + 2747762695, 3402504553, 3772830893, 4120988587, 2163214728, + 2816384844, 3427077306, 153380495, 1551745920, 3646982597, + 910208076, 4011470445, 2926416934, 2915145307, 1712568902, + 3254469058, 3181055693, 3191729660, 2039073006, 1684602222, + 1812852786, 2815256116, 746745227, 735241234, 1296707006, + 3032444839, 3424291161, 136721026, 1359573808, 1189375152, + 3747053250, 198304612, 640439652, 417177801, 4269491673, + 3536724425, 3530047642, 2984266209, 537655879, 1361931891, + 3280281326, 4081172609, 2107063880, 147944788, 2850164008, + 1884392678, 540721923, 1638781099, 902841100, 3287869586, + 219972873, 3415357582, 156513983, 802611720, 1755486969, + 2103522059, 1967048444, 1913778154, 2094092595, 2775893247, + 3410096536, 3046698742, 3955127111, 3241354600, 3468319344, + 1185518681, 3031277329, 2919300778, 12105075, 2813624502, + 3052449900, 698412071, 2765791248, 511091141, 1958646067, + 2140457296, 3323948758, 4122068897, 2464257528, 1461945556, + 3765644424, 2513705832, 3471087299, 961264978, 76338300, + 3226667454, 3527224675, 1095625157, 3525484323, 2173068963, + 4037587209, 3002511655, 1772389185, 3826400342, 1817480335, + 4120125281, 2495189930, 2350272820, 678852156, 595387438, + 3271610651, 641212874, 988512770, 1105989508, 3477783405, + 3610853094, 4245667946, 1092133642, 1427854500, 3497326703, + 1287767370, 1045931779, 58150106, 3991156885, 933029415, + 1503168825, 3897101788, 844370145, 3644141418, 1078396938, + 4101769245, 2645891717, 3345340191, 2032760103, 4241106803, + 1510366103, 290319951, 3568381791, 3408475658, 2513690134, + 2553373352, 2361044915, 3147346559, 3939316793, 2986002498, + 1227669233, 2919803768, 3252150224, 1685003584, 3237241796, + 2411870849, 1634002467, 893645500, 2438775379, 2265043167, + 325791709, 1736062366, 231714000, 1515103006, 2279758133, + 2546159170, 3346497776, 1530490810, 4011545318, 4144499009, + 557942923, 663307952, 2443079012, 1696117849, 2016017442, + 1663423246, 51119001, 3122246755, 1447930741, 1668894615, + 696567687, 3983551422, 3411426125, 1873110678, 1336658413, + 3705174600, 2270032533, 2664425968, 711455903, 513451233, + 2585492744, 2027039028, 1129453058, 1461232481, 2809248324, + 2275654012, 2960153730, 3075629128, 3213286615, 4245057188, + 1935061435, 3094495853, 360010077, 3919490483, 983448591, + 2171099548, 3922754098, 2397746050, 654458600, 2161184684, + 3546856898, 1986311591, 2312163142, 2347594600, 4278366025, + 1922360368, 335761339, 3669839044, 1901288696, 2595154464, + 458070173, 2141230976, 4131320786, 4208748424, 19903848, + 147391738, 3328215103, 4196191786, 3510290616, 1559873971, + 3731015357, 2918514861, 362649214, 1487061100, 1717053387, + 3675955720, 1116134897, 193529268, 3436267940, 2835191639, + 1852908272, 3220971953, 3911201640, 571213604, 781027019, + 4219206494, 1133024903, 409547355, 625085180, 1214072539, + 584409985, 3445042528, 3733581611, 333104904, 2489812253, + 2694595213, 2361631596, 34763086, 622576118, 2921810672, + 3663740744, 2293225236, 2671706445, 1884059696, 1507329019, + 857065948, 2204390003, 592711182, 1725752375, 1642107460, + 326274448, 3274574484, 1030432041, 173822100, 529650788, + 1086437636, 789877945, 2167974914, 1030588245, 3533061365, + 1792148406, 4216468704, 213264131, 3536714075, 3877136173, + 1296338417, 4057830103, 205919137, 2108245233, 1064497347, + 2101324080, 2336703164, 1450493809, 3812754708, 3865701845, + 1476779561, 1585902852, 142887412, 477612192, 699530444, + 3351157089, 3768249319, 1673915577, 903239649, 1038056164, + 1171465372, 1734789440, 2115022236, 414269055, 959581346, + 566820984, 2105828892, 4046076449, 4101450561, 4106566571, + 2800184123, 2470502098, 3253453343, 256751188, 1869365987, + 1008372035, 2374606708, 1516804538, 228288551, 3527001547, + 1385173098, 66157275, 1739381798, 184785808, 3901692666, + 725806641, 3475217997, 2787929747, 1109372433, 3142723729, + 557686578, 2782047723, 2118822689, 1936702581, 1625646963, + 2349385293, 3085804937, 1272688179, 1236112995, 3198431244, + 2677635414, 811555596, 3486972196, 2949678043, 1342211552, + 788174404, 1656614077, 1582629285, 1477167035, 2687011245, + 3503701453, 3351051324, 2874557775, 348432514, 1629591495, + 3991682351, 1969229192, 3331660584, 1304012077, 2090754125, + 3910846836, 1871998370, 2098597104, 1918921592, 3246092887, + 1315760974, 464122393, 2184028058, 1690455542, 2193747147, + 3737423698, 3511684278, 1549884962, 3413774919, 3938991454, + 2767325310, 2335626851, 1626114941, 601913200, 3485711542, + 858447440, 2288468476, 4075602213, 1506361431, 4252489875, + 4032981007, 1031118352, 3762145731, 70955369, 2362903502, + 1669089455, 2673510137, 3348740333, 2521337794, 2047144929, + 892246357, 2319875070, 1293843163, 79245769, 2022600352, + 3866257397, 989939126, 835351312, 3626278636, 3805332945, + 836506264, 1895040349, 970326679, 634920763, 733185481, + 1028655248, 977810701, 3434484235, 1871311609, 2031584214, + 1336174158, 385787519, 3965885375, 2768323462, 1847726660, + 2718987737, 793780050, 2509902580, 3886434164, 3120956802, + 4207987247, 1523159183, 1884932179, 2922324286, 477253416, + 3037922812, 1108379444, 697195677, 1755438379, 574393398, + 2555059183, 1930828628, 1126190880, 180621093, 2589191337, + 3424652760, 3054648512, 719646637, 952394946, 3570038180, + 504304985, 1395707758, 1274213163, 2816553213, 1369142370, + 1804702100, 1821782344, 3358274235, 2181234724, 486158240, + 367287522, 4267199121, 1127352639, 779850007, 3440331597, + 3276765484, 125500149, 1142120513, 3989398167, 1048565860, + 3136747194, 432668526, 2098559576, 1478877150, 2484746208, + 1209580219, 1019125185, 4160278734, 1970740713, 918146921, + 4136433784, 2602441845, 2348512686, 973030509, 2238261365, + 815637919, 994690313, 1724736366, 2099799816, 1775069742, + 2680317667, 730798472, 2916864943, 1284417767, 1698724919, + 2733611686, 1578128411, 651006053, 4243350375, 3303874296, + 162087183, 3796616231, 3801767645, 4119825424, 3922537059, + 77594039, 3419583692, 2503306160, 423966005, 3293613218, + 1124728190, 1407880681, 1440346680, 554334954, 2919409323, + 1253962019, 586491243, 3638308238, 3097648541, 991125519, + 458538714, 2155963569, 2807866455, 6862945, 2122460897, + 53853750, 3346001678, 1230879976, 3071060893, 423909157, + 3881450262, 1652511030, 3826483009, 1526211009, 1435219366, + 3092251623, 3001090498, 281084412, 849586749, 2207008400, + 131172352, 1820973075, 3195774605, 2962673849, 2147580010, + 1090677336, 2061249893, 1724513375, 3885752424, 1135918139, + 2619357288, 4012575714, 2652856935, 2029480458, 3691276589, + 2623865075, 3459550738, 2097670126, 2477000057, 2209844713, + 785646024, 1052349661, 1030500157, 1430246618, 3807539761, + 2157629976, 123154542, 2560049331, 2104110449, 1332109867, + 721241591, 4136042859, 4203401395, 998151922, 3060999432, + 3207929139, 2149509272, 1385268511, 2023309182, 1366796638, + 256061060, 4090836236, 2929047008, 2296609403, 182240337, + 3744374619, 306855912, 4014087816, 2240468995, 2865233169, + 415452309, 1244206523, 3513921306, 281425419, 3511338031, + 995954022, 3102854413, 3026765331, 643667197, 837979907, + 2832983005, 1813414171, 2227348307, 4020325887, 4178893912, + 610818241, 2787397224, 2762441380, 3437393657, 2030369078, + 1949046312, 1876612561, 1857107382, 1049344864, 3544695775, + 2172907342, 358500115, 3895295219, 571965125, 328582064, + 744698407, 3066193991, 1679065087, 2650874932, 3570748805, + 812110431, 3450423805, 1705023874, 259721746, 1192558045, + 1714799045, 3685508436, 2262914445, 3903852862, 1790140070, + 2651193482, 2821191752, 776610414, 2697125035, 2212010032, + 1254062056, 3541766210, 1853927671, 1543286708, 66516686, + 3505195914, 4226521519, 1260092911, 717982876, 739240369, + 456195732, 2116515161, 1599487648, 838913496, 850912042, + 3712172413, 2103192411, 877020153, 1458113119, 2646869271, + 4087221703, 3771198399, 3952796001, 1685641891, 226245966, + 4065518354, 3169076409, 715963611, 1155859114, 4174181651, + 1816065125, 2422210778, 2353087594, 2569974907, 4049024520, + 563593555, 1794197249, 2434290377, 4222178191, 2381045132, + 1294739153, 1333544226, 3011196239, 518183212, 2861903570, + 3168787443, 2315530531, 1042490149, 2998340365, 3534153126, + 2862715604, 796613230, 765073073, 1342937225, 549817636, + 3786981820, 4291017601, 2895722553, 734959362, 3175258828, + 140019477, 268621172, 2410334776, 565052604, 3787587805, + 386344800, 2874086067, 35710270, 817904650, 1960697289, + 1584484509, 2724312018, 1978802819, 2275314726, 4216102886, + 2138332912, 671754166, 1442240992, 3674442465, 1085868016, + 2769242611, 1003628378, 1616076847, 743729558, 820011032, + 2559719034, 1839332599, 3121982280, 2070268989, 3769147733, + 518022934, 3037227899, 2531915367, 1008310588, 971468687, + 2052976098, 1651926578, 78218926, 2503907441, 3209763057, + 1081499040, 2812016370, 1247433164, 335294964, 2650385171, + 2030527826, 1139372809, 4279827824, 3540669095, 2285341455, + 4220507154, 3863048231, 3136394663, 3319584205, 1476940506, + 875141230, 2508558662, 3896001866, 462864388, 1609807693, + 3892563868, 3642514037, 3778083990, 1403162576, 3512254868, + 1403323269, 1119818229, 2831288053, 2552740643, 2520136409, + 96690857, 210381252, 1826474872, 3306977352, 1343117402, + 2112059492, 693571694, 2096734379, 767794921, 1843084587, + 1816280216, 1695342628, 404711915, 3334843684, 2570639553, + 4186538211, 2022604264, 3214805180, 2989079529, 2725165355, + 3005995436, 310011850, 2742468706, 2720274646, 144327376, + 2271696819, 295519962, 1272030376, 1372670420, 1397272558, + 2280044719, 2710639434, 2810822904, 4271368265, 1750711132, + 2216408539, 3521792518, 3111505866, 3085328191, 1054735512, + 4160317205, 1427385632, 2282061755, 3215251668, 1396490078, + 2933318719, 453673969, 2926038256, 2624047458, 338625410, + 3344930154, 1971116345, 1818716442, 2998517928, 390083048, + 291563131, 1144486353, 296954266, 659950561, 2263631666, + 1206908601, 1125491020, 1890151284, 2076080514, 2264060846, + 561805191, 1964622705, 405620012, 3759692386, 517035386, + 2225016848, 4165419081, 4052828294, 3248204933, 2738939733, + 1151808775, 4113264137, 3113447491, 1033828852, 1785686386, + 2903923175, 2038900010, 1241522880, 238119113, 2885394101, + 2636011022, 2985605703, 2107193353, 292026696, 3884689974, + 1094315383, 4016714705, 962244585, 3943968050, 2868319718, + 1304919603, 3626636694, 3393461291, 1479454799, 971639318, + 3352306399, 1928233566, 2900529135, 2190901098, 28842068, + 990556577, 2586302532, 3057504668, 1661169605, 4228191763, + 3934152427, 2814119472, 4943754, 1171095774, 1986204006, + 2014406505, 1822565279, 12890078, 1979620724, 1917376192, + 3307810835, 4170173371, 1385005883, 1308519769, 3370429606, + 923886311, 2024463563, 1063369787, 153599761, 3463680785, + 755374878, 2088947962, 3099927142, 1750207400, 2033606872, + 926120766, 655932557, 2320365045, 1465119024, 3105365454, + 2608716819, 1218456091, 823539591, 2331574954, 3171519129, + 3246671799, 1043031086, 1425831588, 3940307546, 3443545749, + 1155610704, 3681098065, 3287797558, 63959365, 810297004, + 3800799806, 1234795257, 2547289014, 391329364, 370300179, + 2474800443, 3972311925, 2935022755, 3924395679, 2347599539, + 4212318274, 1828491430, 3865565525, 2767860661, 4078993078, + 2781496513, 4013741232, 2916354756, 35752471, 2730683119, + 3340599926, 4059491907, 111492530, 897368671, 2524912702, + 3046341697, 2790787159, 1014602604, 1409764839, 512802978, + 477082227, 2608350570, 533747000, 1933326657, 4182933327, + 1970210993, 2290203137, 2843031053, 2844558050, 3308351089, + 3041943368, 1504174920, 295229952, 2843309586, 884572473, + 1787387521, 1861566286, 3616058184, 48071792, 3577350513, + 297480282, 1101405687, 1473439254, 2634793792, 1341017984); + + Errors: Natural; +begin + for R in 1..2 loop + Put_Line("RUN " & Natural'Image(R) & ": Generating numbers..."); + + Errors := 0; + for I in 0 .. No-1 loop + X := MTS.Gen_U32; + Put("."); + if X /= Result(I) then + Put_Line(""); + Put_Line("ERROR at position " & Integer'Image(I) & + "; expected " & Unsigned_32'Image(Result(I)) & + " but result is " & Unsigned_32'Image(X)); + Errors := Errors + 1; + end if; + end loop; + if Errors /= 0 then + Put_Line("FAIL: " & Natural'Image(Errors) & " errors found."); + else + Put_Line("PASS: no errors found."); + end if; + -- re-initialize the prng + MTS.Reset_Generator; + end loop; + +end Tests_MT; diff -uNr a/mt_generic_pkg/testmt/tests_mt.gpr b/mt_generic_pkg/testmt/tests_mt.gpr --- a/mt_generic_pkg/testmt/tests_mt.gpr false +++ b/mt_generic_pkg/testmt/tests_mt.gpr cf4eb98a6be3a379f871f87aee40ac21b15aa228fb6aead54a7f9db1f6f8b830ffdc16b2eace07426eccc10c5395e0b473d441c597870fef4e362855050af2f6 @@ -0,0 +1,44 @@ + -- Tests for Ada implementation of the Mersenne Twister PRNG + -- S.MG, 2018 + -- + -- Tests results against published PRNG numbers at + -- www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html + +with "../mt.gpr"; + +project Tests_MT is + + for Main use ("tests_mt.adb"); + + type Mode_Type is ("debug", "release"); + Mode : Mode_Type := external ("mode", "release"); + + for Languages use ("Ada"); + for Source_Dirs use ("."); + for Object_Dir use "obj"; + for Exec_Dir use "."; + + package Compiler is + case Mode is + when "debug" => + for Switches ("Ada") + use ("-g"); + when "release" => + for Switches ("Ada") + use ("-O2", "-fdump-scos", "-gnata", "-fstack-check", + "-gnatyd", "-gnatym", "-fdata-sections", + "-ffunction-sections", "-gnatwr", "-gnatw.d"); + end case; + end Compiler; + + package Binder is + case Mode is + when "debug" => + for Switches ("Ada") + use (); + when "release" => + for Switches ("Ada") + use ("-static"); + end case; + end Binder; +end Tests_MT;