91 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// <random>10 11// template <class UIntType, UIntType a, UIntType c, UIntType m>12// class linear_congruential_engine;13 14// result_type operator()();15 16#include <random>17#include <cassert>18 19#include "test_macros.h"20 21template <class T>22void23randu()24{25 typedef std::linear_congruential_engine<T, 65539, 0, 2147483648u> E;26 E e(1);27 assert(e() == 65539);28 assert(e() == 393225);29 assert(e() == 1769499);30 assert(e() == 7077969);31 assert(e() == 26542323);32 assert(e() == 95552217);33 assert(e() == 334432395);34 assert(e() == 1146624417);35 assert(e() == 1722371299);36 assert(e() == 14608041);37 assert(e() == 1766175739);38 assert(e() == 1875647473);39}40 41template <class T>42void43minstd()44{45 typedef std::linear_congruential_engine<T, 16807, 0, 2147483647> E;46 E e(1);47 assert(e() == 16807);48 assert(e() == 282475249);49 assert(e() == 1622650073);50 assert(e() == 984943658);51 assert(e() == 1144108930);52 assert(e() == 470211272);53 assert(e() == 101027544);54 assert(e() == 1457850878);55 assert(e() == 1458777923);56 assert(e() == 2007237709);57 assert(e() == 823564440);58 assert(e() == 1115438165);59}60 61template <class T>62void63Haldir()64{65 typedef std::linear_congruential_engine<T, 16807, 78125, 2147483647> E;66 E e(207560540);67 assert(e() == 956631177);68 assert(e() == 2037688522);69 assert(e() == 1509348670);70 assert(e() == 1546336451);71 assert(e() == 429714088);72 assert(e() == 217250280);73}74 75int main(int, char**)76{77 randu<unsigned int>();78 randu<unsigned long>();79 randu<unsigned long long>();80 81 minstd<unsigned int>();82 minstd<unsigned long>();83 minstd<unsigned long long>();84 85 Haldir<unsigned int>();86 Haldir<unsigned long>();87 Haldir<unsigned long long>();88 89 return 0;90}91