77 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// void discard(unsigned long long z);15 16#include <random>17#include <cassert>18 19#include "test_macros.h"20 21template <class T>22void23rand0()24{25 typedef std::linear_congruential_engine<T, 16807, 0, 2147483647> E;26 E e;27 e.discard(9999);28 assert(e() == 1043618065);29}30 31template <class T>32void33rand()34{35 typedef std::linear_congruential_engine<T, 48271, 0, 2147483647> E;36 E e;37 e.discard(9999);38 assert(e() == 399268537);39}40 41template <class T>42void43other()44{45 typedef std::linear_congruential_engine<T, 48271, 123465789, 2147483647> E;46 E e1;47 E e2;48 assert(e1 == e2);49 e1.discard(1);50 assert(e1 != e2);51 (void)e2();52 assert(e1 == e2);53 e1.discard(3);54 assert(e1 != e2);55 (void)e2();56 (void)e2();57 (void)e2();58 assert(e1 == e2);59}60 61int main(int, char**)62{63 rand0<unsigned int>();64 rand0<unsigned long>();65 rand0<unsigned long long>();66 67 rand<unsigned int>();68 rand<unsigned long>();69 rand<unsigned long long>();70 71 other<unsigned int>();72 other<unsigned long>();73 other<unsigned long long>();74 75 return 0;76}77