diff --git a/Lidgren.Network/NetRandom.Implementations.cs b/Lidgren.Network/NetRandom.Implementations.cs index e0da470..2d104ac 100644 --- a/Lidgren.Network/NetRandom.Implementations.cs +++ b/Lidgren.Network/NetRandom.Implementations.cs @@ -8,15 +8,24 @@ namespace Lidgren.Network /// public class MWCRandom : NetRandom { + /// + /// Get global instance of MWCRandom + /// public static new readonly MWCRandom Instance = new MWCRandom(); private uint m_w, m_z; + /// + /// Constructor with randomized seed + /// public MWCRandom() { Initialize(NetRandomSeed.GetUInt64()); } + /// + /// (Re)initialize this instance with provided 32 bit seed + /// [CLSCompliant(false)] public override void Initialize(uint seed) { @@ -24,6 +33,9 @@ namespace Lidgren.Network m_z = seed * 16777619; } + /// + /// (Re)initialize this instance with provided 64 bit seed + /// [CLSCompliant(false)] public void Initialize(ulong seed) { @@ -31,6 +43,9 @@ namespace Lidgren.Network m_z = (uint)(seed >> 32); } + /// + /// Generates a random value from UInt32.MinValue to UInt32.MaxValue, inclusively + /// [CLSCompliant(false)] public override uint NextUInt32() { @@ -45,6 +60,9 @@ namespace Lidgren.Network /// public sealed class XorShiftRandom : NetRandom { + /// + /// Get global instance of XorShiftRandom + /// public static new readonly XorShiftRandom Instance = new XorShiftRandom(); private const uint c_x = 123456789; @@ -54,17 +72,26 @@ namespace Lidgren.Network private uint m_x, m_y, m_z, m_w; + /// + /// Constructor with randomized seed + /// public XorShiftRandom() { Initialize(NetRandomSeed.GetUInt64()); } + /// + /// Constructor with provided 64 bit seed + /// [CLSCompliant(false)] public XorShiftRandom(ulong seed) { Initialize(seed); } + /// + /// (Re)initialize this instance with provided 32 bit seed + /// [CLSCompliant(false)] public override void Initialize(uint seed) { @@ -74,6 +101,9 @@ namespace Lidgren.Network m_w = c_w; } + /// + /// (Re)initialize this instance with provided 64 bit seed + /// [CLSCompliant(false)] public void Initialize(ulong seed) { @@ -83,6 +113,9 @@ namespace Lidgren.Network m_w = c_w; } + /// + /// Generates a random value from UInt32.MinValue to UInt32.MaxValue, inclusively + /// [CLSCompliant(false)] public override uint NextUInt32() { @@ -97,6 +130,9 @@ namespace Lidgren.Network /// public sealed class MersenneTwisterRandom : NetRandom { + /// + /// Get global instance of MersenneTwisterRandom + /// public static new readonly MersenneTwisterRandom Instance = new MersenneTwisterRandom(); private const int N = 624; @@ -117,17 +153,26 @@ namespace Lidgren.Network private const double c_realUnitInt = 1.0 / ((double)int.MaxValue + 1.0); + /// + /// Constructor with randomized seed + /// public MersenneTwisterRandom() { Initialize(NetRandomSeed.GetUInt32()); } + /// + /// Constructor with provided 32 bit seed + /// [CLSCompliant(false)] public MersenneTwisterRandom(uint seed) { Initialize(seed); } + /// + /// (Re)initialize this instance with provided 32 bit seed + /// [CLSCompliant(false)] public override void Initialize(uint seed) { @@ -139,6 +184,9 @@ namespace Lidgren.Network mt[i] = (UInt32)(1812433253 * (mt[i - 1] ^ (mt[i - 1] >> 30)) + i); } + /// + /// Generates a random value from UInt32.MinValue to UInt32.MaxValue, inclusively + /// [CLSCompliant(false)] public override uint NextUInt32() { @@ -184,6 +232,9 @@ namespace Lidgren.Network /// public class CryptoRandom : NetRandom { + /// + /// Global instance of CryptoRandom + /// public static new readonly CryptoRandom Instance = new CryptoRandom(); private RandomNumberGenerator m_rnd = new RNGCryptoServiceProvider(); @@ -198,6 +249,9 @@ namespace Lidgren.Network m_rnd.GetBytes(tmp); // just prime it } + /// + /// Generates a random value from UInt32.MinValue to UInt32.MaxValue, inclusively + /// [CLSCompliant(false)] public override uint NextUInt32() { @@ -206,11 +260,17 @@ namespace Lidgren.Network return (uint)bytes[0] | (((uint)bytes[1]) << 8) | (((uint)bytes[2]) << 16) | (((uint)bytes[3]) << 24); } + /// + /// Fill the specified buffer with random values + /// public override void NextBytes(byte[] buffer) { m_rnd.GetBytes(buffer); } + /// + /// Fills all bytes from offset to offset + length in buffer with random values + /// public override void NextBytes(byte[] buffer, int offset, int length) { var bytes = new byte[length]; diff --git a/Lidgren.Network/NetRandom.cs b/Lidgren.Network/NetRandom.cs index 82550a4..00b461a 100644 --- a/Lidgren.Network/NetRandom.cs +++ b/Lidgren.Network/NetRandom.cs @@ -9,20 +9,32 @@ namespace Lidgren.Network /// public abstract class NetRandom : Random { + /// + /// Get global instance of NetRandom (uses MWCRandom) + /// public static NetRandom Instance = new MWCRandom(); private const double c_realUnitInt = 1.0 / ((double)int.MaxValue + 1.0); + /// + /// Constructor with randomized seed + /// public NetRandom() { Initialize(NetRandomSeed.GetUInt32()); } + /// + /// Constructor with provided 32 bit seed + /// public NetRandom(int seed) { Initialize((uint)seed); } + /// + /// (Re)initialize this instance with provided 32 bit seed + /// [CLSCompliant(false)] public virtual void Initialize(uint seed) { @@ -154,6 +166,9 @@ namespace Lidgren.Network buffer[ptr++] = (byte)NextUInt32(); } + /// + /// Fill the specified buffer with random values + /// public override void NextBytes(byte[] buffer) { NextBytes(buffer, 0, buffer.Length);