Ranges and random numbers -- again

monarch_dodra monarchdodra at gmail.com
Mon Jun 17 15:36:15 PDT 2013


On Monday, 17 June 2013 at 22:29:34 UTC, Joseph Rushton Wakeling 
wrote:
> On 06/17/2013 11:18 PM, Joseph Rushton Wakeling wrote:
>>> A random range should be viewed (IMO) as nothing more than a 
>>> range that "was"
>>> (conceptually) simply filled with random numbers. Calling 
>>> front on the same
>>> range twice in a row *should* produce the same result: No 
>>> call to popFront => no
>>> change to the range. If it did change, it'd be a blatant 
>>> violation of the range
>>> concept. It also means you can't have safe/nothrow/pure/const 
>>> "front".
>> 
>> Completely agree, and I don't think this is in contradiction 
>> with what I've
>> proposed.  My proposed "rule" might be better stated to 
>> clarify this.
>
> Perhaps this would be a better statement:
>
>     
> ************************************************************************
>     * Iterating fully over a given random range should produce 
> a different *
>     * sequence for each such complete iteration.
>            *
>     
> ************************************************************************

I'm not sure what that means but...

> So, if you do,
>
>     SomeRandomRange r;
>     x = r.front;
>     y = r.front;
>     assert(x == y);  // Passes!!
>
> But
>
>     SomeRandomRange r;
>     arr1 = array(r);
>     arr2 = array(r);
>     assert(x != y);  // the two arrays are filled with 
> different sequences.

With reference ranges, that is indeed what you'd get.

I could even add:

      SomeRandomForwardRange r;
      auto arr1 = array(r.save);
      auto arr2 = array(r);
      assert(x == y); // This time both are the same


More information about the Digitalmars-d mailing list