How can I convert a uniform distribution (as most random number generators produce, e.g. between 0.0 and 1.0) into a normal distribution? What if I want a mean and standard deviation of my choosing?
相关问题
- Finding k smallest elements in a min heap - worst-
- binary search tree path list
- High cost encryption but less cost decryption
- Unity - Get Random Color at Spawning
- How to get a fixed number of evenly spaced points
相关文章
- What are the problems associated to Best First Sea
- Coin change DP solution to keep track of coins
- why 48 bit seed in util Random class?
- Algorithm for partially filling a polygonal mesh
- Robust polygon normal calculation
- Should client-server code be written in one “proje
- Algorithm for maximizing coverage of rectangular a
- Need help generating discrete random numbers from
This is a Matlab implementation using the polar form of the Box-Muller transformation:
Function
randn_box_muller.m
:And invoking
histfit(randn_box_muller(10000000),100);
this is the result:Obviously it is really inefficient compared with the Matlab built-in randn.
The Ziggurat algorithm is pretty efficient for this, although the Box-Muller transform is easier to implement from scratch (and not crazy slow).
I would use Box-Muller. Two things about this:
Typically, you cache one value and return the other. On the next call for a sample, you return the cached value.
You have to then scale the Z-score by the standard deviation and add the mean to get the full value in the normal distribution.