Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9072


Ignore:
Timestamp:
12/18/12 13:03:12 (12 years ago)
Author:
mkommend
Message:

#1890: Added parameter with default value for source count in RandomEnumerable.SampleRandomWithoutRepetition.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Random/3.3/RandomEnumerable.cs

    r7828 r9072  
    121121    /// <param name="random">The random number generator to use, its NextDouble() method must produce values in the range [0;1)</param>
    122122    /// <param name="count">The number of items to be selected.</param>
     123    /// <param name="sourceCount">Optional parameter specifying the number of elements in the source enumerations</param>
    123124    /// <returns>A sequence of elements that have been chosen randomly.</returns>
    124     public static IEnumerable<T> SampleRandomWithoutRepetition<T>(this IEnumerable<T> source, IRandom random, int count) {
    125       int remaining = source.Count();
     125    public static IEnumerable<T> SampleRandomWithoutRepetition<T>(this IEnumerable<T> source, IRandom random, int count, int sourceCount = -1) {
     126      if (sourceCount == -1) sourceCount = source.Count();
     127      int remaining = sourceCount;
    126128      foreach (var item in source) {
    127129        if (random.NextDouble() * remaining < count) {
Note: See TracChangeset for help on using the changeset viewer.