mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-07-02 14:04:09 +00:00
fix libs/random/example/array.cpp
This commit is contained in:
parent
9d938bd747
commit
a5b7eda260
5 changed files with 205 additions and 207 deletions
|
@ -1,53 +1,53 @@
|
|||
//
|
||||
// Sprout C++ Library
|
||||
//
|
||||
// Copyright (c) 2013
|
||||
// bolero-MURAKAMI : http://d.hatena.ne.jp/boleros/
|
||||
// osyo-manga : http://d.hatena.ne.jp/osyo-manga/
|
||||
//
|
||||
// Readme:
|
||||
// https://github.com/bolero-MURAKAMI/Sprout/blob/master/README
|
||||
//
|
||||
// License:
|
||||
// Boost Software License - Version 1.0
|
||||
// <http://www.boost.org/LICENSE_1_0.txt>
|
||||
//
|
||||
#include <sprout/random.hpp>
|
||||
|
||||
//
|
||||
// Compile Time Random
|
||||
//
|
||||
int
|
||||
main(){
|
||||
//
|
||||
// Random engine
|
||||
//
|
||||
static constexpr sprout::hellekalek1995 engine;
|
||||
static_assert(engine() == 2110608584, "");
|
||||
static_assert(engine()() == 239248507, "");
|
||||
|
||||
//
|
||||
// Distribution
|
||||
//
|
||||
static constexpr sprout::uniform_int_distribution<int> dist(100, 999);
|
||||
|
||||
//
|
||||
// Get random value
|
||||
//
|
||||
// return int value
|
||||
static constexpr int n = *dist(engine);
|
||||
// or
|
||||
// operator int
|
||||
// static constexpr int n = dist(engine);
|
||||
static_assert(n == 984, "");
|
||||
|
||||
//
|
||||
// Next random value
|
||||
//
|
||||
static_assert(dist(engine)() == 200, "");
|
||||
static_assert(dist(engine)()() == 566, "");
|
||||
static_assert(dist(engine)()()() == 255, "");
|
||||
static_assert(dist(engine)()()()() == 175, "");
|
||||
|
||||
return 0;
|
||||
}
|
||||
//
|
||||
// Sprout C++ Library
|
||||
//
|
||||
// Copyright (c) 2013
|
||||
// bolero-MURAKAMI : http://d.hatena.ne.jp/boleros/
|
||||
// osyo-manga : http://d.hatena.ne.jp/osyo-manga/
|
||||
//
|
||||
// Readme:
|
||||
// https://github.com/bolero-MURAKAMI/Sprout/blob/master/README
|
||||
//
|
||||
// License:
|
||||
// Boost Software License - Version 1.0
|
||||
// <http://www.boost.org/LICENSE_1_0.txt>
|
||||
//
|
||||
#include <sprout/random.hpp>
|
||||
|
||||
//
|
||||
// Compile Time Random
|
||||
//
|
||||
int
|
||||
main(){
|
||||
//
|
||||
// Random engine
|
||||
//
|
||||
static constexpr sprout::hellekalek1995 engine;
|
||||
static_assert(engine() == 2110608584, "");
|
||||
static_assert(engine()() == 239248507, "");
|
||||
|
||||
//
|
||||
// Distribution
|
||||
//
|
||||
static constexpr sprout::uniform_int_distribution<int> dist(100, 999);
|
||||
|
||||
//
|
||||
// Get random value
|
||||
//
|
||||
// return int value
|
||||
static constexpr int n = *dist(engine);
|
||||
// or
|
||||
// operator int
|
||||
// static constexpr int n = dist(engine);
|
||||
static_assert(n == 984, "");
|
||||
|
||||
//
|
||||
// Next random value
|
||||
//
|
||||
static_assert(dist(engine)() == 200, "");
|
||||
static_assert(dist(engine)()() == 566, "");
|
||||
static_assert(dist(engine)()()() == 255, "");
|
||||
static_assert(dist(engine)()()()() == 175, "");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue