Evolution/Evolution/Utils/RandomChooser.cs
/// <summary>
/// Returns an enumerable generated by randomly sorting another finite enumerable
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source">The source.</param>
/// <returns></returns>
/// <remarks>The source is expected to be finite</remarks>
Returns an enumerable generated by randomly sorting another finite enumerable
Returns an enumerable generated by randomly sorting another finite enumerable
public static IEnumerable<T> RandomSort<T>(this IEnumerable<T> source)
        {
            List<T> destination = new List<T>();
            foreach (T item in source)
            {
                int rnd = RandomGenerator.GetInstance().NextInt(0, destination.Count + 1);
                if (rnd == destination.Count)
                {
                    destination.Add(item);
                }
                else
                {
                    destination.Add(destination[rnd]);
                    destination[rnd] = item;
                }
            }
            return destination;
        }
public static IEnumerable < T > RandomSort < T > ( this IEnumerable < T > source ) { List < T > destination = new List < T > ( ) ; foreach ( T item in source ) { int rnd = RandomGenerator . GetInstance ( ) . NextInt ( 0 , destination . Count + 1 ) ; if ( rnd == destination . Count ) { destination . Add ( item ) ; } else { destination . Add ( destination [ rnd ] ) ; destination [ rnd ] = item ; } } return destination ; }
Returns an enumerable generated by randomly sorting another finite enumerable
Returns an enumerable generated by randomly sorting another finite enumerable
None
IEnumerable<T>
this
source
None
typeparam
None
remarks
The source is expected to be finite
The source is expected to be finite