diff --git a/MLEM/Misc/SeedSource.cs b/MLEM/Misc/SeedSource.cs
index ba686ee..fb3a95c 100644
--- a/MLEM/Misc/SeedSource.cs
+++ b/MLEM/Misc/SeedSource.cs
@@ -12,23 +12,6 @@ namespace MLEM.Misc {
private readonly int? value;
- ///
- /// Creates a new seed source from the given seed, which will be added automatically using .
- ///
- /// The initial seed to use.
- public SeedSource(int seed) : this() {
- this = this.Add(seed);
- }
-
- ///
- /// Creates a new seed source from the given set of seeds, which will be added automatically using .
- ///
- /// The initial seeds to use.
- public SeedSource(params int[] seeds) : this() {
- foreach (var seed in seeds)
- this = this.Add(seed);
- }
-
private SeedSource(int? value) {
this.value = value;
}
@@ -40,7 +23,7 @@ namespace MLEM.Misc {
/// The seed to add.
/// A new seed source with the seed added.
public SeedSource Add(int seed) {
- return new SeedSource(new int?(SeedSource.Scramble(this.Get()) + SeedSource.Scramble(seed)));
+ return new SeedSource(SeedSource.Scramble(this.Get()) + SeedSource.Scramble(seed));
}
///
@@ -66,13 +49,36 @@ namespace MLEM.Misc {
return ret;
}
+ ///
+ /// Adds the given seed to this seed source's value and returns the result as a new seed source.
+ /// Guids are scrambled by invoking using every byte in the 's byte array.
+ ///
+ /// The seed to add.
+ /// A new seed source with the seed added.
+ public SeedSource Add(Guid seed) {
+ var ret = this;
+ foreach (var b in seed.ToByteArray())
+ ret = ret.Add(b);
+ return ret;
+ }
+
+ ///
+ /// Adds the given seed to this seed source's value and returns the result as a new seed source.
+ /// Any objects that don't have a specially defined overload get scrambled using .
+ ///
+ /// The seed to add.
+ /// A new seed source with the seed added.
+ public SeedSource Add(object seed) {
+ return this.Add(seed?.GetHashCode() ?? 0);
+ }
+
///
/// Returns a new seed source whose value is this seed source's value, but scrambled further.
/// In essence, this creates a new seed source whose value is determined by the current seed source.
///
/// A new seed source with a rotated value.
public SeedSource Rotate() {
- return new SeedSource(new int?(SeedSource.Scramble(this.Get())));
+ return new SeedSource(SeedSource.Scramble(this.Get()));
}
///
diff --git a/MLEM/Misc/SingleRandom.cs b/MLEM/Misc/SingleRandom.cs
index a5b08d0..73f7299 100644
--- a/MLEM/Misc/SingleRandom.cs
+++ b/MLEM/Misc/SingleRandom.cs
@@ -79,7 +79,7 @@
/// The seed to use.
/// The generated number.
public static float Single(int seed) {
- return (new SeedSource(seed).Get() / (float) int.MaxValue + 1) / 2;
+ return (new SeedSource().Add(seed).Get() / (float) int.MaxValue + 1) / 2;
}
///
diff --git a/Tests/SingleRandomTests.cs b/Tests/SingleRandomTests.cs
index 470daf9..15398b5 100644
--- a/Tests/SingleRandomTests.cs
+++ b/Tests/SingleRandomTests.cs
@@ -13,9 +13,7 @@ public class SingleRandomTests {
public void TestEquality() {
for (var i = 0; i < 1000000; i++) {
Assert.AreEqual(SingleRandom.Single(i), SingleRandom.Single(new SeedSource().Add(i)));
- Assert.AreEqual(SingleRandom.Single(i), SingleRandom.Single(new SeedSource(i)));
Assert.AreEqual(SingleRandom.Int(i), SingleRandom.Int(new SeedSource().Add(i)));
- Assert.AreEqual(SingleRandom.Int(i), SingleRandom.Int(new SeedSource(i)));
// test if all methods that accept mins and max are identical
Assert.AreEqual(SingleRandom.Int(i), SingleRandom.Int(int.MaxValue, i));