rng-Random number generator

Source: Internet
Author: User

RNG Random number generator

RNG g_rng (12345);

/******************************************************************************************************/

The friends who make the algorithm with OpenCV must worry about the random number, the new version has always supported the random number generator, but also continues to support the previous version of the C format function, but with the times, I introduce the RNG class C + +. It can compress a 64-bit I integer and get a random number of scalar and array. The current version supports uniformly distributed random numbers and Gaussian distributed random numbers. The generation of random numbers is based on the Multiply-with-carry algorithm and the ziggurat algorithm.

The initialization of its constructor can pass in a 64-bit integer parameter as the initial value of the random number generator. Next can take the next random number, the uniform function can return a random number of the specified range, the Gaussian function returns a Gaussian random number, and fill fills the matrix with random numbers.

Here is a description of the use of a uniform, such as using it to generate 0~1 random number problem, the specific code is as follows:

RNG rng;
Always produces 0
Double A = rng.uniform (0, 1);
produces double from [0, 1)
Double A1 = Rng.uniform ((double) 0, (double) 1);
produces float from [0, 1)
Double b = rng.uniform (0.F, 1.F);
produces double from [0, 1)
Double c = rng.uniform (0., 1.);
May cause compiler error because of ambiguity:
Rng::uniform (0, (int) 0.999999)? or Rng::uniform (double) 0,0.99999)?
Double d = rng.uniform (0, 0.999999);

Just can't write Rng.uniform (0, 1), because the input is an int parameter, it will call uniform (int,int), can only produce 0. Please pay attention to the use of ^_^

There are also some random number related functions, such as randu can produce a uniformly distributed random number or matrix, RANDN can produce a normal distribution of random numbers, randshuffle can randomly disrupt the matrix element

Briefly introduce the C version of the random number generator related functions, there are cvrng, Cvrandarr, Cvrandint, Cvrandreal

"Turn" http://blog.csdn.net/yang_xian521/article/details/6931385

rng-Random number generator

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.