isUniformRNG

Nick Sabalausky via Digitalmars-d digitalmars-d at puremagic.com
Wed May 7 13:06:08 PDT 2014


On 5/4/2014 3:26 PM, Joseph Rushton Wakeling via Digitalmars-d wrote:
> On 04/05/14 20:56, Nick Sabalausky via Digitalmars-d wrote:
>> So I think it's probably safe to figure this is a uniform distribution
>> unless
>> some expert chimes in and says otherwise.
>>
>> Thanks for the help.
>
> You're very welcome.  Keep me posted on how things go with your
> implementation! :-)
>

It's now implemented and working in DAuth's HEAD:

https://github.com/Abscissa/DAuth/blob/master/src/dauth/hashdrbg.d

Usage is pretty simple:

----------------------------
import std.algorithm : take;
import std.array : array;
import dauth.sha;
import dauth.hashdrbg;

HashDRBG!uint rand;

// The above is equivalent to:
// HashDRBG!(uint, SHA512, "DAuth") rand;

// Now use rand just like any other RNG in std.random:
uint[] values1 = rand.take(7).array();

// The algorithm specifically supports generating
// arbitrary lengths at once, so can also do:
HashDRBGStream!uint randStream;

ubyte[] values2;
values2.length = 42;

randStream.read(values2);
----------------------------

Next steps are to support Hash_DRBG's optional "additional input" 
feature, and to see about Phobos-ifying it and making a pull request.

I'll take a look at your proposed std.random too, sorry I haven't had a 
chance to yet.



More information about the Digitalmars-d mailing list