Normal/Gaussian random number generation for D

jerro a at a.com
Sun Nov 11 08:30:57 PST 2012


> What's wrong with such initialization being in the constructor 
> of the relevant NormalEngine?  I think that was your original 
> idea, and I derailed it because of my misunderstanding of what 
> you wanted to initialize.

The problem is that structs can't have constructors with no 
parameters.

> In general the idea is that the engine should be something 
> hidden; where you need to use it, you just need to pass the 
> name as a template parameter; it should be rare that you really 
> need to manually instantiate your own engine. But we can add 
> such a helper function if you like.

I agree that those helper functions are not very important, but 
on the other hand I don't think adding them costs us anything. 
But maybe we should take care of the other stuff first.

> What I'm frustrated about is that as-is it's not possible to 
> just have
>
>     auto nrng = Normal(mean, sigma);
>
> ... but you have instead to write,
>
>     auto nrng = Normal!()(mean, sigma);
>
> despite the fact that Normal has default template parameters 
> given.  So maybe a helper function normalRNG which returns an 
> instance of Normal would also be helpful.

Yes, I think it would be.

> I've uploaded a tweaked version based on your comments here:
> https://github.com/WebDrake/phobos/tree/normal
>
> ... so feel free to pull, further revise and add in your 
> Ziggurat implementation :-)

I'll add the Zigggurat implementation, probably tomorrow.




More information about the Digitalmars-d mailing list