1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-12-25 09:49:23 +01:00

improved SeedSource algorithm to be less predictable

This commit is contained in:
Ell 2022-11-30 21:31:34 +01:00
parent 0a62ae0036
commit e3b41ebeea
3 changed files with 20008 additions and 20005 deletions

View file

@ -181,13 +181,7 @@ namespace MLEM.Misc {
/// <param name="seed">The seed to add.</param>
/// <returns>A new seed source with the seed added.</returns>
public SeedSource Add(int seed) {
seed ^= seed << 7;
seed *= 207398809;
seed ^= seed << 17;
seed *= 928511849;
seed ^= seed << 12;
seed += 3;
return new SeedSource(new int?(this.Get() + seed));
return new SeedSource(new int?(SeedSource.Scramble(this.Get()) + SeedSource.Scramble(seed)));
}
/// <summary>
@ -229,5 +223,14 @@ namespace MLEM.Misc {
return new Random(this.Get());
}
private static int Scramble(int x) {
x += 84317;
x ^= x << 7;
x *= 207398809;
x ^= x << 17;
x *= 928511849;
return x;
}
}
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff