Different random shuffles generated when compiled with gdc than with dmd
Andrew Brown via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri May 30 06:39:17 PDT 2014
Hi there,
The following code:
void main(){
import std.array : array;
import std.stdio : writeln;
import std.random : rndGen, randomShuffle;
import std.range : iota;
rndGen.seed(12);
int[] temp = iota(10).array;
randomShuffle(temp);
writeln(temp);
}
writes [1, 8, 4, 2, 0, 7, 5, 6, 9, 3] if it's compiled with dmd,
but [1, 7, 4, 6, 2, 9, 5, 0, 3, 8] with gdc.
I'd like to allow the users to specify an integer if they wish to
give a deterministic set of permutations. This won't matter if I
only distribute a binary created with a given compiler (aside
from scaring me into thinking I need to know more about random
number generation), but it's an annoyance when I'm trying to
check my code is doing what it should.
Is there a better way to specify an integer seed so both
compilers will agree on the permutations they generate?
Thanks very much
Andrew
More information about the Digitalmars-d-learn
mailing list