mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-10 14:44:11 +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,60 +1,60 @@
|
|||
//
|
||||
// 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>
|
||||
#include <iostream>
|
||||
|
||||
int
|
||||
main(){
|
||||
//
|
||||
// Random engine
|
||||
//
|
||||
static constexpr sprout::default_random_engine engine;
|
||||
|
||||
//
|
||||
// Distribution
|
||||
//
|
||||
// 1 ~ 6
|
||||
{
|
||||
static constexpr sprout::uniform_int_distribution<> dist(1, 6);
|
||||
static_assert(dist(engine) == 1, "");
|
||||
static_assert(dist(engine)() == 1, "");
|
||||
static_assert(dist(engine)()() == 5, "");
|
||||
static_assert(dist(engine)()()() == 3, "");
|
||||
}
|
||||
|
||||
// 0.0 ~ 1.0
|
||||
{
|
||||
static constexpr sprout::uniform_real_distribution<double> dist(0.0, 1.0);
|
||||
// static_assert(dist(engine) == 0.7.8259e-006, "");
|
||||
// static_assert(dist(engine) == 0.131538, "");
|
||||
// static_assert(dist(engine) == 0.755605, "");
|
||||
// static_assert(dist(engine) == 0.45865, "");
|
||||
std::cout << dist(engine) << std::endl;
|
||||
std::cout << dist(engine)() << std::endl;
|
||||
std::cout << dist(engine)()() << std::endl;
|
||||
std::cout << dist(engine)()()() << std::endl;
|
||||
}
|
||||
|
||||
// Returns true with probability 50%
|
||||
{
|
||||
static constexpr sprout::bernoulli_distribution<> dist(0.5);
|
||||
static_assert(dist(engine) == 1, "");
|
||||
static_assert(dist(engine)() == 1, "");
|
||||
static_assert(dist(engine)()() == 0, "");
|
||||
static_assert(dist(engine)()()() == 1, "");
|
||||
}
|
||||
|
||||
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>
|
||||
#include <iostream>
|
||||
|
||||
int
|
||||
main(){
|
||||
//
|
||||
// Random engine
|
||||
//
|
||||
static constexpr sprout::default_random_engine engine;
|
||||
|
||||
//
|
||||
// Distribution
|
||||
//
|
||||
// 1 ~ 6
|
||||
{
|
||||
static constexpr sprout::uniform_int_distribution<> dist(1, 6);
|
||||
static_assert(dist(engine) == 1, "");
|
||||
static_assert(dist(engine)() == 1, "");
|
||||
static_assert(dist(engine)()() == 5, "");
|
||||
static_assert(dist(engine)()()() == 3, "");
|
||||
}
|
||||
|
||||
// 0.0 ~ 1.0
|
||||
{
|
||||
static constexpr sprout::uniform_real_distribution<double> dist(0.0, 1.0);
|
||||
// static_assert(dist(engine) == 0.7.8259e-006, "");
|
||||
// static_assert(dist(engine) == 0.131538, "");
|
||||
// static_assert(dist(engine) == 0.755605, "");
|
||||
// static_assert(dist(engine) == 0.45865, "");
|
||||
std::cout << dist(engine) << std::endl;
|
||||
std::cout << dist(engine)() << std::endl;
|
||||
std::cout << dist(engine)()() << std::endl;
|
||||
std::cout << dist(engine)()()() << std::endl;
|
||||
}
|
||||
|
||||
// Returns true with probability 50%
|
||||
{
|
||||
static constexpr sprout::bernoulli_distribution<> dist(0.5);
|
||||
static_assert(dist(engine) == 1, "");
|
||||
static_assert(dist(engine)() == 1, "");
|
||||
static_assert(dist(engine)()() == 0, "");
|
||||
static_assert(dist(engine)()()() == 1, "");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue