Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/16/09 11:24:03 (15 years ago)
Author:
vdorfer
Message:

Created API documentation for HeuristicLab.Random, HeuristicLab.SGA and HeuristicLab.Selection.OffspringSelection namespace (#331)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Random/MersenneTwister.cs

    r2 r1153  
    3939
    4040namespace HeuristicLab.Random {
     41  /// <summary>
     42  /// A 623-Dimensionally Equidistributed Uniform Pseudo-Random Number Generator.
     43  /// </summary>
    4144  public class MersenneTwister : ItemBase, IRandom {
    4245    private const int n = 624, m = 397;
     
    4750    private bool init = false;
    4851
     52    /// <summary>
     53    /// Initializes a new instance of <see cref="MersenneTwister"/>.
     54    /// </summary>
    4955    public MersenneTwister() {
    5056      if (!init) seed((uint)DateTime.Now.Ticks);
    5157      init = true;
    5258    }
     59    /// <summary>
     60    /// Initializes a new instance of <see cref="MersenneTwister"/>
     61    /// with the given seed <paramref name="s"/>.
     62    /// </summary>
     63    /// <param name="s">The seed with which to initialize the random number generator.</param>
    5364    public MersenneTwister(uint s) {
    5465      seed(s);
    5566      init = true;
    5667    }
     68    /// <summary>
     69    /// Initializes a new instance of <see cref="MersenneTwister"/> with the given seed array.
     70    /// </summary>
     71    /// <param name="array">The seed array with which to initialize the random number generator.</param>
    5772    public MersenneTwister(uint[] array) {
    5873      seed(array);
     
    6075    }
    6176
     77    /// <summary>
     78    /// Clones the current instance (deep clone).
     79    /// </summary>
     80    /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
     81    /// <returns>The cloned object as <see cref="MersenneTwister"/>.</returns>
    6282    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    6383      MersenneTwister clone = new MersenneTwister();
     
    6989    }
    7090
     91    /// <summary>
     92    /// Resets the current random number generator.
     93    /// </summary>
    7194    public void Reset() {
    7295      lock (locker)
    7396        seed((uint)DateTime.Now.Ticks);
    7497    }
     98    /// <summary>
     99    /// Resets the current random number generator with the given seed <paramref name="s"/>.
     100    /// </summary>
     101    /// <param name="s">The seed with which to reset the current instance.</param>
    75102    public void Reset(int s) {
    76103      lock (locker)
     
    78105    }
    79106
     107    /// <summary>
     108    /// Gets a new random number.
     109    /// </summary>
     110    /// <returns>A new int random number.</returns>
    80111    public int Next() {
    81112      lock (locker) {
     
    83114      }
    84115    }
     116    /// <summary>
     117    /// Gets a new random number being smaller than the given <paramref name="maxVal"/>.
     118    /// </summary>
     119    /// <exception cref="ArgumentException">Thrown when the given maximum value is
     120    /// smaller or equal to zero.</exception>
     121    /// <param name="maxVal">The maximum value of the generated random number.</param>
     122    /// <returns>A new int random number.</returns>
    85123    public int Next(int maxVal) {
    86124      lock (locker) {
     
    93131      }
    94132    }
     133    /// <summary>
     134    /// Gets a new random number being in the given interval <paramref name="minVal"/> and
     135    /// <paramref name="maxVal"/>.
     136    /// </summary>
     137    /// <param name="minVal">The minimum value of the generated random number.</param>
     138    /// <param name="maxVal">The maximum value of the generated random number.</param>
     139    /// <returns>A new int random number.</returns>
    95140    public int Next(int minVal, int maxVal) {
    96141      lock (locker) {
     
    100145      }
    101146    }
     147    /// <summary>
     148    /// Gets a new double random variable.
     149    /// </summary>
     150    /// <returns></returns>
    102151    public double NextDouble() {
    103152      lock (locker) {
     
    107156
    108157    #region Persistence Methods
     158    /// <summary>
     159    /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
     160    /// </summary>
     161    /// <remarks>The state(s) are saved as child node with the tag <c>State</c>, each state separaated with
     162    /// a semicolon. Also the elements <c>p</c> and the <c>init</c> flag are saved as child nodes with
     163    /// tag names <c>P</c> and <c>Init</c> respectively.</remarks>
     164    /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
     165    /// <param name="document">The <see cref="XmlDocument"/> where the data is saved.</param>
     166    /// <param name="persistedObjects">A dictionary of all already persisted objects. (Needed to avoid cycles.)</param>
     167    /// <returns>The saved <see cref="XmlNode"/>.</returns>
    109168    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
    110169      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
     
    130189      return node;
    131190    }
     191    /// <summary>
     192    /// Loads the persisted random number generator from the specified <paramref name="node"/>.
     193    /// </summary>
     194    /// <remarks>The elements of the current instance must be saved in a special way, see
     195    /// <see cref="GetXmlNode"/>.</remarks>
     196    /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param>
     197    /// <param name="restoredObjects">The dictionary of all already restored objects. (Needed to avoid cycles.)</param>
    132198    public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
    133199      base.Populate(node, restoredObjects);
     
    143209
    144210    #region Seed Methods
     211    /// <summary>
     212    /// Initializes current instance with random seed.
     213    /// </summary>
     214    /// <param name="s">A starting seed.</param>
    145215    public void seed(uint s) {
    146216      state[0] = s & 0xFFFFFFFFU;
     
    151221      p = n;
    152222    }
     223    /// <summary>
     224    /// Initializes current instance with random seed.
     225    /// </summary>
     226    /// <param name="array">A starting seed array.</param>
    153227    public void seed(uint[] array) {
    154228      seed(19650218U);
Note: See TracChangeset for help on using the changeset viewer.