1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-18 08:06:33 +09:00

XML comments provided for random classes to stomp out last warnings

This commit is contained in:
lidgren
2014-08-25 07:42:43 +00:00
parent f2aa4b4ce2
commit 7440f6da3c
2 changed files with 75 additions and 0 deletions

View File

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

View File

@@ -9,20 +9,32 @@ namespace Lidgren.Network
/// </summary> /// </summary>
public abstract class NetRandom : Random public abstract class NetRandom : Random
{ {
/// <summary>
/// Get global instance of NetRandom (uses MWCRandom)
/// </summary>
public static NetRandom Instance = new MWCRandom(); public static NetRandom Instance = new MWCRandom();
private const double c_realUnitInt = 1.0 / ((double)int.MaxValue + 1.0); private const double c_realUnitInt = 1.0 / ((double)int.MaxValue + 1.0);
/// <summary>
/// Constructor with randomized seed
/// </summary>
public NetRandom() public NetRandom()
{ {
Initialize(NetRandomSeed.GetUInt32()); Initialize(NetRandomSeed.GetUInt32());
} }
/// <summary>
/// Constructor with provided 32 bit seed
/// </summary>
public NetRandom(int seed) public NetRandom(int seed)
{ {
Initialize((uint)seed); Initialize((uint)seed);
} }
/// <summary>
/// (Re)initialize this instance with provided 32 bit seed
/// </summary>
[CLSCompliant(false)] [CLSCompliant(false)]
public virtual void Initialize(uint seed) public virtual void Initialize(uint seed)
{ {
@@ -154,6 +166,9 @@ namespace Lidgren.Network
buffer[ptr++] = (byte)NextUInt32(); buffer[ptr++] = (byte)NextUInt32();
} }
/// <summary>
/// Fill the specified buffer with random values
/// </summary>
public override void NextBytes(byte[] buffer) public override void NextBytes(byte[] buffer)
{ {
NextBytes(buffer, 0, buffer.Length); NextBytes(buffer, 0, buffer.Length);