Skip to content

Commit

Permalink
Use all bytes of string for initialising MersenneTwister
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisJefferson committed Aug 21, 2018
1 parent a1f8928 commit 044db55
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/intfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Obj FuncInitRandomMT( Obj self, Obj initstr)
mt[i] &= 0xffffffffUL;
i++; j++;
if (i>=N) { mt[0] = mt[N-1]; i=1; }
if (j>=key_length) j=0;
if (4 * j >= byte_key_length) j=0;
}
for (k=N-1; k; k--) {
mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL)) - i;
Expand Down
25 changes: 25 additions & 0 deletions tst/testinstall/random.tst
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,30 @@ gap> randomTest([1,-6,"cheese", Group(())], Random);
gap> randomTest(PadicExtensionNumberFamily(3, 5, [1,1,1], [1,1]), Random, function(x,y) return IsPadicExtensionNumber(x); end);
gap> randomTest(PurePadicNumberFamily(2,20), Random, function(x,y) return IsPurePadicNumber(x); end);

# Test initialising random number generator
# We take a string and 0-pad it to 4 bytes
gap> getOneInt := function(str)
> Init(GlobalMersenneTwister, str);
> return Random([1..100000]);
> end;;
gap> getOneInt("") = getOneInt("\000");
true
gap> getOneInt("a") = getOneInt("b");
false
gap> getOneInt("") = getOneInt("\000\000\000\000");
true
gap> getOneInt("a") = getOneInt("a\000");
true
gap> getOneInt("a") = getOneInt("a\000\000\000");
true
gap> getOneInt("a") = getOneInt("a\000\000\000\000");
false
gap> getOneInt("a") = getOneInt("a\000\000\000a\000\000\000");
false
gap> getOneInt("a\000\000\000a\000\000\000") = getOneInt("a\000\000\000a");
true
gap> getOneInt("a") = getOneInt("a\000\000\000b");
false

#
gap> STOP_TEST("random.tst", 1);

0 comments on commit 044db55

Please sign in to comment.