std::mersenne_twister_engine and random number generation

前端 未结 4 1526
野趣味
野趣味 2021-01-20 16:49

What is the distribution (uniform, poisson, normal, etc.) that is generated if I did the below? The output appears to indicate a uniform distribution. But then, why do we ne

4条回答
  •  温柔的废话
    2021-01-20 16:54

    One of the major accomplishments of was the separation of distributions from engines.

    I see it as similar to Alexander Stepanov's STL, which separated algorithms from containers through the use of iterators. For random numbers I can do an implementation of the Blum-Blum-Shub single bit generator (engine) and it will still work with all the distributions in . Or, I can do a simple Linear Congruential Generator, x_{n + 1} = a * x_{n} % m, which when correctly seeded can never generate 0. Again, it will work with all the distributions. Likewise, I can write a new distribution and I don't have to worry about the peculiarities of any engine as long as I only use the interface specified by a UniformRandomBitGenerator.

    In general, you should always use a distribution. Also, it is time to retire using '%' for generating random numbers.

提交回复
热议问题