(v) random number of boost libraries

Source: Internet
Author: User

(v) random number of boost libraries

The Boost library provides us with a number of daily random number generators:

1.uniform_smallint: Uniform distribution within a small integer field
2.uniform_int: Uniform distribution on integer fields
3.UNIFORM_01: Continuous uniform distribution of real numbers on the interval [0,1]
4.uniform_real: Continuous uniform distribution of real numbers on the interval [Min,max]
5.bernoulli_distribution: Bernoulli distribution
6.binomial_distribution: Two distributions
7.cauchy_distribution: Cauchy (Lorentz) distribution
8.gamma_distribution: Gamma distribution
9.poisson_distribution: Poisson distribution
10.geometric_distribution: Geometric distribution
11.triangle_distribution: Triangular distribution
12.exponential_distribution: Exponential distribution
13.normal_distribution: Normal Distribution
14.lognormal_distribution: Logarithmic normal distribution
15.uniform_on_sphere: Spherical uniform distribution

The random number generation consists of two parts, one is the random number seed, the other is the generator, and for the random number seed, the use of boost::random::mt19937 is sufficient.

#include <iostream>
#include <boost/random.hpp>
#include <boost/random/random_device.hpp>
Boost:: Random:: mt19937 gen;  
_tchar* argv[])
{
    {
        Integer
        Boost::uniform_int<> Real (999); 
        std:std:: Endl; 
    }
    
    {
        Real
        Boost::uniform_real<Double> real (5);   
        std:std:: Endl; 
    }
    
    {
        real numbers on 0-1
        Boost:: uniform_01<boost::mt19937&> u01 (gen);  
        Normal distribution, with the parameters mean, variance, respectively
        Boost::normal_distribution<> nd (1); 
        std:std:: Endl; 
    }
    Boost:: Random::uniform_int_distribution<> Dist (+);   
    std:std:: Endl; 
    std:std:: Endl; 
    std::string chars ( 
        "abcdefghijklmnopqrstuvwxyz" 
        "abcdefghijklmnopqrstuvwxyz" 
        "1234567890" 
        "[email protected]#$%^&* ()]" 
        "");
    Boost:: Random:: Random_device rng;  
    Boost:: Random::uniform_int_distribution<> index_dist (1);   
    8; ++i) {
        std:: cout << chars[index_dist (RNG)];
    }
    0;
}

(v) random number of boost libraries

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.