Good libraries for generating non-uniform pseudo random numbers

I am looking for well-known libraries that can generate unevenly distributed random numbers for C, C ++ and Java.

thanks

+3
source share
7 answers

The GNU Science Library (GSL), http://www.gnu.org/software/gsl/ , provides many uneven random distributions — see Chapter 19 of the Manual, “Distributing Random Numbers”. (Unified random number generators are given in Chapter 17, "Generating Random Numbers"). Implementation is done in C.

+2
source

I got some interesting answers in this related question:

Estimated Sources of Random Numbers

+5

Java Uncommons Maths. , , , . WebStart, , .

+3

Alglib, , .

+2

Boost , .

+1

.

0
source

With C ++ 11, there are many new options for creating non-uniform pseudorandom numbers in the random header . The code example below demonstrates possible non-uniform distributions:

#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <random>

int main()
{
    std::random_device rd;

    std::mt19937 e2(rd());

    //
    // Distribtuions
    //
    std::normal_distribution<> dist(2, 2);
    //std::student_t_distribution<> dist(5);
    //std::poisson_distribution<> dist(2);
    //std::extreme_value_distribution<> dist(0,2);
    //std::lognormal_distribution<> dist(1.6, 0.25);
    //std::exponential_distribution<> dist(1);

    std::map<int, int> hist;
    for (int n = 0; n < 10000; ++n) {
        ++hist[std::round(dist(e2))];
    }

    for (auto p : hist) {
        std::cout << std::fixed << std::setprecision(1) << std::setw(2)
                  << p.first << ' ' << std::string(p.second/200, '*') << '\n';
    }
}

using the normal distribution, you will see output similar to this:

-5 
-4 
-3 
-2 *
-1 ***
 0 ******
 1 ********
 2 *********
 3 ********
 4 ******
 5 ***
 6 *
 7 
 8 
 9 
0
source

Source: https://habr.com/ru/post/1722176/


All Articles