File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -146,5 +146,33 @@ public static bool Implements<T>(this object obj)
146146 {
147147 return obj . GetType ( ) . GetInterfaces ( ) . Contains ( typeof ( T ) ) ;
148148 }
149+
150+ /// <summary>
151+ /// Returns a list with <paramref name="count"/> random elements from <paramref name="sequence"/>.
152+ /// </summary>
153+ /// <typeparam name="T"><see cref="Type"/> of the element.</typeparam>
154+ /// <param name="sequence"><see cref="IEnumerable{T}"/></param>
155+ /// <param name="count">Number of random elements.</param>
156+ /// <returns>List of random elements.</returns>
157+ public static List < T > SelectRandomElements < T > ( this IEnumerable < T > sequence , int count ) where T : class
158+ {
159+ List < T > ret = new List < T > ( ) ;
160+
161+ if ( count >= sequence . Count ( ) )
162+ return sequence . ToList ( ) ;
163+
164+ if ( count < 1 )
165+ return null ;
166+
167+ while ( ret . Count < count )
168+ {
169+ var select = sequence . SelectRandomElement ( ) ;
170+
171+ if ( ! ret . Contains ( select ) )
172+ ret . Add ( select ) ;
173+ }
174+
175+ return ret ;
176+ }
149177 }
150178}
Original file line number Diff line number Diff line change 22<package >
33 <metadata >
44 <id >FusionLibrary.SHVDN3</id >
5- <version >1.2.0 </version >
5+ <version >1.2.2 </version >
66 <authors >MrFusion92</authors >
77 <requireLicenseAcceptance >true</requireLicenseAcceptance >
88 <license type =" expression" >MIT</license >
You can’t perform that action at this time.
0 commit comments