Jump to page: 1 2 3
Thread overview
Different random shuffles generated when compiled with gdc than with dmd
May 30, 2014
Andrew Brown
May 30, 2014
Wanderer
May 30, 2014
Andrew Brown
May 30, 2014
monarch_dodra
May 30, 2014
Andrew Brown
May 31, 2014
Russel Winder
May 31, 2014
Dicebot
May 30, 2014
monarch_dodra
May 31, 2014
Andrew Brown
Jun 01, 2014
Ivan Kazmenko
Jun 01, 2014
Andrew Brown
Jun 02, 2014
Chris Cain
Jun 02, 2014
Chris Cain
Jun 02, 2014
Andrew Brown
Jun 02, 2014
Kagamin
May 30, 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
May 30, 2014
I must note if the sequence is predictable, it's not random anymore, it's pseudo-random at most.

Also, if anyone interested, PHP had such way to generate predictable sequences in the past, but after it was horribly misused by various people for crypto keys/password generation purposes, they have forbidden it completely, so only non-predictable sequences in PHP from now on. Maybe, just maybe, it makes sense not to stand on the same rack twice.
May 30, 2014
I'd like it to be predictable given the seed, right now it's predictable given the seed and the compiler. Is this a bug, shouldn't the random number process be completely defined in the language?

I'm not trying to misuse it like the PHP crowd :) It's for a piece of scientific software: I'm hoping people will test the significance of their results with a stochastic process, and for reproducibility we need to allow other people to recreate their analysis exactly (hence the seed). For my purposes I don't need truly random, I just need it not to repeat too quickly.

Thanks

Andrew

On Friday, 30 May 2014 at 14:09:20 UTC, Wanderer wrote:
> I must note if the sequence is predictable, it's not random anymore, it's pseudo-random at most.
>
> Also, if anyone interested, PHP had such way to generate predictable sequences in the past, but after it was horribly misused by various people for crypto keys/password generation purposes, they have forbidden it completely, so only non-predictable sequences in PHP from now on. Maybe, just maybe, it makes sense not to stand on the same rack twice.

May 30, 2014
On Friday, 30 May 2014 at 13:39:18 UTC, Andrew Brown wrote:
> 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.
>
> ...
>
> Andrew

Are you sure you are compiling with the same version of dmd and gdc? Fixes were made to the rand.d library in the latest release, which could explain the difference you are observing.
May 30, 2014
GDC version 4.8.2,i guess that's my problem. This is what happens
when you let Ubuntu look after your packages.

Thank you very much!

Andrew

On Friday, 30 May 2014 at 16:13:49 UTC, monarch_dodra wrote:
> On Friday, 30 May 2014 at 13:39:18 UTC, Andrew Brown wrote:
>> 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.
>>
>> ...
>>
>> Andrew
>
> Are you sure you are compiling with the same version of dmd and gdc? Fixes were made to the rand.d library in the latest release, which could explain the difference you are observing.
May 30, 2014
On 30/05/14 18:13, monarch_dodra via Digitalmars-d-learn wrote:
> Are you sure you are compiling with the same version of dmd and gdc? Fixes were
> made to the rand.d library in the latest release, which could explain the
> difference you are observing.

Which fixes are you thinking of here ... ?  I don't recall anything that ought to alter the behaviour of the standard random number generator.

May 30, 2014
On Friday, 30 May 2014 at 18:41:55 UTC, Joseph Rushton Wakeling via Digitalmars-d-learn wrote:
> On 30/05/14 18:13, monarch_dodra via Digitalmars-d-learn wrote:
>> Are you sure you are compiling with the same version of dmd and gdc? Fixes were
>> made to the rand.d library in the latest release, which could explain the
>> difference you are observing.
>
> Which fixes are you thinking of here ... ?  I don't recall anything that ought to alter the behaviour of the standard random number generator.

Didn't you make changes to how and when the global PRNG is popped and accessed in randomShuffle? I figured it *could* be an explanation.
May 31, 2014
On Fri, 2014-05-30 at 16:44 +0000, Andrew Brown via Digitalmars-d-learn wrote:
> GDC version 4.8.2,i guess that's my problem. This is what happens when you let Ubuntu look after your packages.

Debian Sid has GCC 4.9 packages, but that may not help?

-- 
Russel. ============================================================================= Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net 41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@winder.org.uk London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

May 31, 2014
On Saturday, 31 May 2014 at 06:54:13 UTC, Russel Winder via Digitalmars-d-learn wrote:
> On Fri, 2014-05-30 at 16:44 +0000, Andrew Brown via Digitalmars-d-learn
> wrote:
>> GDC version 4.8.2,i guess that's my problem. This is what happens
>> when you let Ubuntu look after your packages.
>
> Debian Sid has GCC 4.9 packages, but that may not help?

There is currently no GDC version with same frontend as latest DMD relese.
May 31, 2014
Looking at old data, it is the dmd version that's changed, so I think this is the likely reason.

Andrew

On Friday, 30 May 2014 at 20:45:23 UTC, monarch_dodra wrote:
> On Friday, 30 May 2014 at 18:41:55 UTC, Joseph Rushton Wakeling via Digitalmars-d-learn wrote:
>> On 30/05/14 18:13, monarch_dodra via Digitalmars-d-learn wrote:
>>> Are you sure you are compiling with the same version of dmd and gdc? Fixes were
>>> made to the rand.d library in the latest release, which could explain the
>>> difference you are observing.
>>
>> Which fixes are you thinking of here ... ?  I don't recall anything that ought to alter the behaviour of the standard random number generator.
>
> Didn't you make changes to how and when the global PRNG is popped and accessed in randomShuffle? I figured it *could* be an explanation.

« First   ‹ Prev
1 2 3