Look and think good things about D

bearophile bearophileHUGS at lycos.com
Sun Nov 17 09:02:41 PST 2013


> What function do you suggest? (It should be possible to 
> implement on 32-64bit systems, in Haskell, in languages with 
> only multi-precision integers, in languages like Ada that give 
> errors on overflows, and in Java without unsigned integers).

The Computer Shootout site uses this one:


int nextRandom() nothrow {
     enum int IM = 139968, IA = 3877, IC = 29573;
     __gshared static int last = 42;
     return last = (last * IA + IC) % IM;
}

void main() {
     import std.stdio;

     foreach (i; 0 .. 100) {
         nextRandom.writeln;
     }
}


Bye,
bearophile


More information about the Digitalmars-d mailing list