[DEV] add v1.66.0

This commit is contained in:
2018-01-12 21:47:58 +01:00
parent 87059bb1af
commit a97e9ae7d4
49032 changed files with 7668950 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
# Jamfile.v2
#
# Copyright (c) 2009
# Steven Watanabe
#
# Distributed under the Boost Software License, Version 1.0. (See
# accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
run die.cpp ;
run weighted_die.cpp ;
run password.cpp /boost//random ;

View File

@@ -0,0 +1,60 @@
// die.cpp
//
// Copyright (c) 2009
// Steven Watanabe
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//[die
/*`
For the source of this example see
[@boost://libs/random/example/die.cpp die.cpp].
First we include the headers we need for __mt19937
and __uniform_int_distribution.
*/
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int_distribution.hpp>
/*`
We use __mt19937 with the default seed as a source of
randomness. The numbers produced will be the same
every time the program is run. One common method to
change this is to seed with the current time (`std::time(0)`
defined in ctime).
*/
boost::random::mt19937 gen;
/*`
[note We are using a /global/ generator object here. This
is important because we don't want to create a new [prng
pseudo-random number generator] at every call]
*/
/*`
Now we can define a function that simulates an ordinary
six-sided die.
*/
int roll_die() {
/*<< __mt19937 produces integers in the range [0, 2[sup 32]-1].
However, we want numbers in the range [1, 6]. The distribution
__uniform_int_distribution performs this transformation.
[warning Contrary to common C++ usage __uniform_int_distribution
does not take a /half-open range/. Instead it takes a /closed range/.
Given the parameters 1 and 6, __uniform_int_distribution
can produce any of the values 1, 2, 3, 4, 5, or 6.]
>>*/
boost::random::uniform_int_distribution<> dist(1, 6);
/*<< A distribution is a function object. We generate a random
number by calling `dist` with the generator.
>>*/
return dist(gen);
}
//]
#include <iostream>
int main() {
for(int i = 0; i < 10; ++i) {
std::cout << roll_die() << std::endl;
}
}

View File

@@ -0,0 +1,48 @@
// password.cpp
//
// Copyright (c) 2010
// Steven Watanabe
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//[password
/*`
For the source of this example see
[@boost://libs/random/example/password.cpp password.cpp].
This example demonstrates generating a random 8 character
password.
*/
#include <boost/random/random_device.hpp>
#include <boost/random/uniform_int_distribution.hpp>
int main() {
/*<< We first define the characters that we're going
to allow. This is pretty much just the characters
on a standard keyboard.
>>*/
std::string chars(
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"1234567890"
"!@#$%^&*()"
"`~-_=+[{]}\\|;:'\",<.>/? ");
/*<< We use __random_device as a source of entropy, since we want
passwords that are not predictable.
>>*/
boost::random::random_device rng;
/*<< Finally we select 8 random characters from the
string and print them to cout.
>>*/
boost::random::uniform_int_distribution<> index_dist(0, chars.size() - 1);
for(int i = 0; i < 8; ++i) {
std::cout << chars[index_dist(rng)];
}
std::cout << std::endl;
}
//]

View File

@@ -0,0 +1,110 @@
/* boost random_demo.cpp profane demo
*
* Copyright Jens Maurer 2000
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* $Id$
*
* A short demo program how to use the random number library.
*/
#include <iostream>
#include <fstream>
#include <ctime> // std::time
#include <boost/random/linear_congruential.hpp>
#include <boost/random/uniform_int.hpp>
#include <boost/random/uniform_real.hpp>
#include <boost/random/variate_generator.hpp>
#include <boost/generator_iterator.hpp>
// This is a typedef for a random number generator.
// Try boost::mt19937 or boost::ecuyer1988 instead of boost::minstd_rand
typedef boost::minstd_rand base_generator_type;
// This is a reproducible simulation experiment. See main().
void experiment(base_generator_type & generator)
{
// Define a uniform random number distribution of integer values between
// 1 and 6 inclusive.
typedef boost::uniform_int<> distribution_type;
typedef boost::variate_generator<base_generator_type&, distribution_type> gen_type;
gen_type die_gen(generator, distribution_type(1, 6));
// If you want to use an STL iterator interface, use iterator_adaptors.hpp.
boost::generator_iterator<gen_type> die(&die_gen);
for(int i = 0; i < 10; i++)
std::cout << *die++ << " ";
std::cout << '\n';
}
int main()
{
// Define a random number generator and initialize it with a reproducible
// seed.
base_generator_type generator(42);
std::cout << "10 samples of a uniform distribution in [0..1):\n";
// Define a uniform random number distribution which produces "double"
// values between 0 and 1 (0 inclusive, 1 exclusive).
boost::uniform_real<> uni_dist(0,1);
boost::variate_generator<base_generator_type&, boost::uniform_real<> > uni(generator, uni_dist);
std::cout.setf(std::ios::fixed);
// You can now retrieve random numbers from that distribution by means
// of a STL Generator interface, i.e. calling the generator as a zero-
// argument function.
for(int i = 0; i < 10; i++)
std::cout << uni() << '\n';
/*
* Change seed to something else.
*
* Caveat: std::time(0) is not a very good truly-random seed. When
* called in rapid succession, it could return the same values, and
* thus the same random number sequences could ensue. If not the same
* values are returned, the values differ only slightly in the
* lowest bits. A linear congruential generator with a small factor
* wrapped in a uniform_smallint (see experiment) will produce the same
* values for the first few iterations. This is because uniform_smallint
* takes only the highest bits of the generator, and the generator itself
* needs a few iterations to spread the initial entropy from the lowest bits
* to the whole state.
*/
generator.seed(static_cast<unsigned int>(std::time(0)));
std::cout << "\nexperiment: roll a die 10 times:\n";
// You can save a generator's state by copy construction.
base_generator_type saved_generator = generator;
// When calling other functions which take a generator or distribution
// as a parameter, make sure to always call by reference (or pointer).
// Calling by value invokes the copy constructor, which means that the
// sequence of random numbers at the caller is disconnected from the
// sequence at the callee.
experiment(generator);
std::cout << "redo the experiment to verify it:\n";
experiment(saved_generator);
// After that, both generators are equivalent
assert(generator == saved_generator);
// as a degenerate case, you can set min = max for uniform_int
boost::uniform_int<> degen_dist(4,4);
boost::variate_generator<base_generator_type&, boost::uniform_int<> > deg(generator, degen_dist);
std::cout << deg() << " " << deg() << " " << deg() << std::endl;
{
// You can save the generator state for future use. You can read the
// state back in at any later time using operator>>.
std::ofstream file("rng.saved", std::ofstream::trunc);
file << generator;
}
return 0;
}

View File

@@ -0,0 +1,55 @@
// weighted_die.cpp
//
// Copyright (c) 2009
// Steven Watanabe
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//[weighted_die
/*`
For the source of this example see
[@boost://libs/random/example/weighted_die.cpp weighted_die.cpp].
*/
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/discrete_distribution.hpp>
boost::mt19937 gen;
/*`
This time, instead of a fair die, the probability of
rolling a 1 is 50% (!). The other five faces are all
equally likely.
__discrete_distribution works nicely here by allowing
us to assign weights to each of the possible outcomes.
[tip If your compiler supports `std::initializer_list`,
you can initialize __discrete_distribution directly with
the weights.]
*/
double probabilities[] = {
0.5, 0.1, 0.1, 0.1, 0.1, 0.1
};
boost::random::discrete_distribution<> dist(probabilities);
/*`
Now define a function that simulates rolling this die.
*/
int roll_weighted_die() {
/*<< Add 1 to make sure that the result is in the range [1,6]
instead of [0,5].
>>*/
return dist(gen) + 1;
}
//]
#include <iostream>
int main() {
for(int i = 0; i < 10; ++i) {
std::cout << roll_weighted_die() << std::endl;
}
}