Skip to content

Commit 4cce768

Browse files
Alinshanssunnycase
authored andcommitted
Fix rng algorithm. (#55)
* Fix rng algorithm. * 更新 Perlin 实现
1 parent b95f0d9 commit 4cce768

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/MineCase.Algorithm/Noise/PerlinNoise.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ public class PerlinNoise : INoise
1313
/// <summary>
1414
/// Permutation
1515
/// </summary>
16-
private readonly int[] _p = new int[512];
16+
private readonly byte[] _p = new byte[512];
1717

1818
/// <summary>
1919
/// Initializes a new instance of the <see cref="PerlinNoise"/> class.
2020
/// </summary>
2121
/// <param name="seed">Seed for generating permutaion.</param>
2222
public PerlinNoise(int seed)
2323
{
24-
var random = new Random(seed);
24+
var random = new UniformRNG((ulong)seed);
2525
for (int i = 0; i < 256; i++)
26-
_p[i + 256] = _p[i] = random.Next(0, 256);
26+
_p[i + 256] = _p[i] = (byte)(random.NextUInt32() % 256);
2727
}
2828

2929
public float Noise(float x, float y, float z)

src/MineCase.Algorithm/UniformRNG.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ public double Uniform(double a, double b)
9797

9898
private uint Next()
9999
{
100+
_state ^= _state >> 13;
101+
_state ^= (_state << 7) | 0x9d2c5680;
102+
_state ^= (_state << 15) & 0xefc67a5b;
100103
_state = _state * _multiplier + _increment;
101104
return (uint)_state;
102105
}

0 commit comments

Comments
 (0)