www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6593] New: final class random generators?

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6593

           Summary: final class random generators?
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



This is a _potential_ enhancement request.


A wrong D2 program:


import std.stdio, std.random;
void foo(RND)(RND rnd) {
    foreach (i; 0 .. 5)
        write(uniform(0, 10, rnd), " ");
    writeln();
}
void main() {
    auto rnd = Xorshift(1);
    foo(rnd);
    foo(rnd);
}


DMD 2.054 output:
3 1 2 7 5 
3 1 2 7 5 


The mistake is a missing ref, that causes foo to not return an updated random
generator, so it always generate the same random values:
void foo(RND)(ref RND rnd) {


To avoid this bug (that I think is common enough), I suggest to experiment if
it's performance-wide possibile to turn all random generators into reference
things, that is final class instances, that don't require that "ref".

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 02 2011
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6593




See also issue 7067

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 05 2011