Skip to content

Commit

Permalink
Double safety check for Xorshift bit values.
Browse files Browse the repository at this point in the history
  • Loading branch information
WebDrake committed Jul 9, 2013
1 parent e1504f7 commit b03552d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions std/random.d
Original file line number Diff line number Diff line change
Expand Up @@ -925,8 +925,8 @@ struct XorshiftEngine(UIntType, UIntType bits, UIntType a, UIntType b, UIntType
seeds_[3] = seeds_[4];
seeds_[4] = seeds_[4] ^ (seeds_[4] >> c) ^ temp ^ (temp >> b);
}
else
{ // 192bits
else static if (bits == 192)
{
temp = seeds_[0] ^ (seeds_[0] >> a);
seeds_[0] = seeds_[1];
seeds_[1] = seeds_[2];
Expand All @@ -935,6 +935,11 @@ struct XorshiftEngine(UIntType, UIntType bits, UIntType a, UIntType b, UIntType
seeds_[4] = seeds_[4] ^ (seeds_[4] << c) ^ temp ^ (temp << b);
value_ = seeds_[4] + (seeds_[5] += 362437);
}
else
{
static assert(false, "Xorshift RNGs are available in 32, 64, 96, 128, 160 or 192 bit versions. "
~ to!string(bits) ~ " is not supported.");
}
}


Expand Down

0 comments on commit b03552d

Please sign in to comment.