File size: 2,696 Bytes
b1b3bae |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
/// ------------------------------------------------------
/// RandomOps - (Pseudo) Random Number Generator For C#
/// Copyright (C) 2003-2010 Magnus Erik Hvass Pedersen.
/// Please see the file license.txt for license details.
/// RandomOps on the internet: http://www.Hvass-Labs.org/
/// ------------------------------------------------------
using System;
namespace RandomOps
{
/// <summary>
/// Pseudo-Random Number Generator (PRNG) base-class for a generator of UInt32 integers
/// that uses an array.
/// </summary>
public abstract class RanUInt32Array : RanUInt32
{
#region Constructors.
/// <summary>
/// Constructs the PRNG-object.
/// </summary>
public RanUInt32Array()
: base()
{
}
/// <summary>
/// Constructs the PRNG-object using the designated seed.
/// This is useful if you want to repeat experiments with the
/// same sequence of pseudo-random numbers.
/// </summary>
public RanUInt32Array(UInt32[] seed)
: base()
{
Seed(seed);
}
/// <summary>
/// Constructs the PRNG-object using another PRNG-object
/// for seeding.
/// </summary>
public RanUInt32Array(Random rand)
: base()
{
Seed(rand);
}
#endregion
#region Seed.
/// <summary>
/// Length of seed-array.
/// </summary>
public abstract int SeedLength
{
get;
}
/// <summary>
/// Seed with an array.
/// </summary>
public abstract void Seed(UInt32[] seed);
/// <summary>
/// Seed with random bytes from another RNG.
/// </summary>
public void Seed(Random rand)
{
UInt32[] seed = new UInt32[SeedLength];
for (int i = 0; i < seed.Length; i++)
{
byte[] b = rand.Bytes(4);
seed[i] = BitConverter.ToUInt32(b, 0);
}
Seed(seed);
}
#endregion
#region Base-class overrides.
/// <summary>
/// Seed with an integer.
/// </summary>
protected sealed override void Seed()
{
throw new NotImplementedException();
}
/// <summary>
/// Seed with an integer.
/// </summary>
protected sealed override void Seed(UInt32 seed)
{
throw new NotImplementedException();
}
#endregion
}
}
|