Ranges and random numbers -- again

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Tue Jun 18 07:54:55 PDT 2013


On 06/18/2013 03:38 PM, H. S. Teoh wrote:
> W.r.t. (P)RNGs, the places where .save is used are where random ranges
> wouldn't really make sense anyway -- if I *really* wanted to search a
> range for a random needle, I'd make an array out of prng.take(n) first,
> and then pass that to find(); it'd be more efficient, if nothing else.
> And I can't think of any useful application of taking a cartesian
> product of a random range.

I'll have a look through these things and see if there are any ways in which
they might reasonably offer a way to come unstuck statistics-wise.

I've attached a little example.  Here we call:

    auto gen = new MtClass19937(unpredictableSeed);
    auto r = simpleRandomRange(0.0L, 1.0L, gen);
    auto t1 = r.take(5);
    auto s = r.save;
    auto t2 = s.take(5);
    writeln(t1);
    writeln(t2);

    auto t3 = r.take(5);
    auto t4 = s.take(5);
    writeln(t3);
    writeln(t4);

Note that the first pair and last pair produce the same output, but the
successive takes from r (t1 and t3) are different from each other, as are the
successive takes from the save s (t2 and t4).  This is what you'd expect, but an
algorithm might assume that repeatedly consuming r.save would result in the same
output again and again and again.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: randomsave.d
Type: text/x-dsrc
Size: 1781 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130618/17682b2c/attachment.d>


More information about the Digitalmars-d mailing list