1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <random> 11 12 // template <class UIntType, UIntType a, UIntType c, UIntType m> 13 // class linear_congruential_engine; 14 15 // result_type operator()(); 16 17 #include <random> 18 #include <cassert> 19 20 template <class T> 21 void 22 randu() 23 { 24 typedef std::linear_congruential_engine<T, 65539, 0, 2147483648u> E; 25 E e(1); 26 assert(e() == 65539); 27 assert(e() == 393225); 28 assert(e() == 1769499); 29 assert(e() == 7077969); 30 assert(e() == 26542323); 31 assert(e() == 95552217); 32 assert(e() == 334432395); 33 assert(e() == 1146624417); 34 assert(e() == 1722371299); 35 assert(e() == 14608041); 36 assert(e() == 1766175739); 37 assert(e() == 1875647473); 38 } 39 40 template <class T> 41 void 42 minstd() 43 { 44 typedef std::linear_congruential_engine<T, 16807, 0, 2147483647> E; 45 E e(1); 46 assert(e() == 16807); 47 assert(e() == 282475249); 48 assert(e() == 1622650073); 49 assert(e() == 984943658); 50 assert(e() == 1144108930); 51 assert(e() == 470211272); 52 assert(e() == 101027544); 53 assert(e() == 1457850878); 54 assert(e() == 1458777923); 55 assert(e() == 2007237709); 56 assert(e() == 823564440); 57 assert(e() == 1115438165); 58 } 59 60 template <class T> 61 void 62 Haldir() 63 { 64 typedef std::linear_congruential_engine<T, 16807, 78125, 2147483647> E; 65 E e(207560540); 66 assert(e() == 956631177); 67 assert(e() == 2037688522); 68 assert(e() == 1509348670); 69 assert(e() == 1546336451); 70 assert(e() == 429714088); 71 assert(e() == 217250280); 72 } 73 74 int main() 75 { 76 randu<unsigned int>(); 77 randu<unsigned long>(); 78 randu<unsigned long long>(); 79 80 minstd<unsigned int>(); 81 minstd<unsigned long>(); 82 minstd<unsigned long long>(); 83 84 Haldir<unsigned int>(); 85 Haldir<unsigned long>(); 86 Haldir<unsigned long long>(); 87 } 88