Pseudo-random numbers in [0, n), covering all numbers in n steps?

Alex Parrill via Digitalmars-d digitalmars-d at puremagic.com
Fri Feb 26 10:28:25 PST 2016


On Friday, 26 February 2016 at 16:45:53 UTC, Andrei Alexandrescu 
wrote:
> On 02/26/2016 10:19 AM, Alex Parrill wrote:
>> On Friday, 26 February 2016 at 14:59:43 UTC, Andrei 
>> Alexandrescu wrote:
>>> On 02/25/2016 06:46 PM, Nicholas Wilson wrote:
>>>> The technical name for the property of distribution you 
>>>> describe is
>>>>   k-Dimensional Equidistribution (in this case k=1).
>>>> I would suggest taking a look at http://www.pcg-random.org.
>>>> They claim to have both arbitrary period and k-Dimensional
>>>> Equidistribution
>>>
>>> Thanks, that's indeed closest! A hefty read. Anyone inclined 
>>> to work
>>> on a PCG random implementation? -- Andrei
>>
>> Beat you to it: http://code.dlang.org/packages/d-pcg
>>
>> It only has the basic generators at the moment. I'll look into 
>> the more
>> advanced stuff.
>>
>> (Also 64 bit outputs aren't implemented yet because they need 
>> a 128 bit
>> uint for state. I noticed D reserves the names cent and ucent 
>> but hasn't
>> implemented them)
>
> That's pretty darn cool! I don't see a way to create a 
> generator given a range expressed as a power of two. Say e.g. a 
> client wants to say "give me a generator with a cycle of 
> 32768". Is this easily doable?
>
> Also: when the generator starts running, does it generate a 
> full cycle, or it starts with a shorter cycle and then settle 
> into a full cycle?
>
>
> Thanks,
>
> Andrei

My port at the moment only provides the basic pgm32 generators; 
their behavior should match the pgm32_* classes from the C++ 
library.

I'll look into which of the generators support the 
equidistributed results, though I suspect that they are 
distributed across the entire domain of the result type.



More information about the Digitalmars-d mailing list