Dconf 2015 talks...

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Mon Jan 25 14:01:00 PST 2016


On Monday, 25 January 2016 at 21:30:47 UTC, Era Scarecrow wrote:
> On Monday, 25 January 2016 at 21:20:09 UTC, Joseph Rushton 
> Wakeling wrote:
>> Right -- non-PRNGs must be input ranges by design.  I came to 
>> the conclusion that pseudo-RNGs need to be input ranges, but 
>> that implement an alternative to .save: a .dup method whose 
>> promise is, "You can duplicate the state and hence behaviour 
>> of this range, but you can't make any assumptions that this is 
>> a safe or sane thing to do."
>
>
>  So in short, the RNG shouldn't be a range at all. Of course it 
> could be a struct (for sanity and other reasons), but not a 
> range.

Why? They work fine as input ranges regardless of whether having 
them be forward ranges make sense. By its very nature, an input 
range cannot be saved, and it's not assumed that it's 
deterministic. The issue that we run into isn't that they're 
ranges but that they're not implemented as reference types, and 
copies of them accidentally get used, resulting in subtle bugs. 
But I'd strongly argue that we should at least consider requiring 
that all input ranges be reference types, since they don't make 
sense as value types, and pseudo-reference types are just plain 
buggy. That's a wider discussion than random number generator 
ranges though.

- Jonathan M Davis


More information about the Digitalmars-d mailing list