Files
libcxx/test/std/numerics/rand/rand.adapt/rand.adapt.shuf/eval.pass.cpp
Chandler Carruth 7c3769df62 Update more file headers across all of the LLVM projects in the monorepo
to reflect the new license. These used slightly different spellings that
defeated my regular expressions.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@351648 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-19 10:56:40 +00:00

95 lines
1.8 KiB
C++

//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t k>
// class shuffle_order_engine
// result_type operator()();
#include <random>
#include <cassert>
#include "test_macros.h"
template <class UIntType, UIntType Min, UIntType Max>
class rand1
{
public:
// types
typedef UIntType result_type;
private:
result_type x_;
static_assert(Min < Max, "rand1 invalid parameters");
public:
#if TEST_STD_VER < 11 && defined(_LIBCPP_VERSION)
// Workaround for lack of constexpr in C++03
static const result_type _Min = Min;
static const result_type _Max = Max;
#endif
static TEST_CONSTEXPR result_type min() {return Min;}
static TEST_CONSTEXPR result_type max() {return Max;}
explicit rand1(result_type sd = Min) : x_(sd)
{
if (x_ > Max)
x_ = Max;
}
result_type operator()()
{
result_type r = x_;
if (x_ < Max)
++x_;
else
x_ = Min;
return r;
}
};
void
test1()
{
typedef std::knuth_b E;
E e;
assert(e() == 152607844u);
}
void
test2()
{
typedef rand1<unsigned long long, 0, 0xFFFFFFFFFFFFFFFFull> E0;
typedef std::shuffle_order_engine<E0, 101> E;
E e;
e.discard(400);
assert(e() == 501);
}
void
test3()
{
typedef rand1<unsigned long long, 0, 0xFFFFFFFFFFFFFFFFull> E0;
typedef std::shuffle_order_engine<E0, 100> E;
E e;
e.discard(400);
assert(e() == 500);
}
int main()
{
test1();
test2();
test3();
}