Normal/Gaussian random number generation for D

jerro a at a.com
Tue Oct 23 07:36:21 PDT 2012


> Using the Ziggurat algorithm is desired, otherwise people will 
> have to implement it outside Phobos, because it's better if you 
> have to generate many normal distributed values (and sometimes 
> I need many of them). is it possible to have both algorithms? 
> Maybe with a template argument?

I have an implementation of the Ziggurat algorithm at 
https://github.com/jerro/phobos/blob/master/std/random.d#L2035. 
It modified the Ziggurat algorithm a bit, so that it doesn't need 
as many layers to work well, which reduces the memory consumption 
and makes initialization faster. The cauchy, normal and 
exponential functions currently use global tables, but the 
zigguratAlgorithm function can also be used to implement a struct 
or class based API.

Joseph mentions having different engines for generating normally 
distributed random numbers, so maybe I could write an engine for 
his API based on what I already have. If we had multiple engines, 
I don't think Ziggurat algorithm should be the default, though, 
because it requires relatively expensive initialization.


More information about the Digitalmars-d mailing list