@@ -222,28 +222,6 @@ static int RandomSelectIndex<T>(int count, IEnumerable<T> source, IEnumerable<T>
222222 public static int RandomSelectIndex < T > ( this IReadOnlyCollection < T > source , IEnumerable < T > exclusion = null )
223223 => RandomSelectIndex ( source . Count , source , exclusion ) ;
224224
225- /// <summary>
226- /// Randomly selects an index from the source.
227- /// Will not return indexes that are contained in the optional exclusion set.
228- /// </summary>
229- /// <typeparam name="T">The generic type of the source.</typeparam>
230- /// <param name="source">The source collection.</param>
231- /// <param name="exclusion">The optional values to exclude from selection.</param>
232- /// <returns>The index selected.</returns>
233- public static int RandomSelectIndex < T > ( this ICollection < T > source , IEnumerable < T > exclusion = null )
234- => RandomSelectIndex ( source . Count , source , exclusion ) ;
235-
236- /// <summary>
237- /// Randomly selects an index from the source.
238- /// Will not return indexes that are contained in the optional exclusion set.
239- /// </summary>
240- /// <typeparam name="T">The generic type of the source.</typeparam>
241- /// <param name="source">The source array.</param>
242- /// <param name="exclusion">The optional values to exclude from selection.</param>
243- /// <returns>The index selected.</returns>
244- public static int RandomSelectIndex < T > ( this T [ ] source , IEnumerable < T > exclusion = null )
245- => RandomSelectIndex ( source . Length , source , exclusion ) ;
246-
247225 /// <summary>
248226 /// Randomly selects an index from the source.
249227 /// Will not return indexes that are contained in the optional exclusion set.
@@ -342,30 +320,6 @@ static int RandomSelectIndexExcept<T>(int count, IEnumerable<T> source, T exclus
342320 public static int RandomSelectIndexExcept < T > ( this IReadOnlyCollection < T > source , T exclusion , params T [ ] others )
343321 => RandomSelectIndexExcept ( source . Count , source , exclusion , others ) ;
344322
345- /// <summary>
346- /// Randomly selects an index from the source.
347- /// Will not return indexes that are contained in the optional exclusion set.
348- /// </summary>
349- /// <typeparam name="T">The generic type of the source.</typeparam>
350- /// <param name="source">The source collection.</param>
351- /// <param name="exclusion">A value to exclude from selection.</param>
352- /// <param name="others">The additional set of optional values to exclude from selection.</param>
353- /// <returns>The index selected.</returns>
354- public static int RandomSelectIndexExcept < T > ( this ICollection < T > source , T exclusion , params T [ ] others )
355- => RandomSelectIndexExcept ( source . Count , source , exclusion , others ) ;
356-
357- /// <summary>
358- /// Randomly selects an index from the source.
359- /// Will not return indexes that are contained in the optional exclusion set.
360- /// </summary>
361- /// <typeparam name="T">The generic type of the source.</typeparam>
362- /// <param name="source">The source array.</param>
363- /// <param name="exclusion">A value to exclude from selection.</param>
364- /// <param name="others">The additional set of optional values to exclude from selection.</param>
365- /// <returns>The index selected.</returns>
366- public static int RandomSelectIndexExcept < T > ( this T [ ] source , T exclusion , params T [ ] others )
367- => RandomSelectIndexExcept ( source . Length , source , exclusion , others ) ;
368-
369323 /// <summary>
370324 /// Attempts to select an index at random from the source and returns the value from it..
371325 /// Will not select indexes that are contained in the optional exclusion set.
@@ -430,52 +384,6 @@ public static T RandomSelectOne<T>(
430384 : source . ElementAt ( index ) ;
431385 }
432386
433- /// <summary>
434- /// Selects an index at random from the source and returns the value from it.
435- /// Will not select indexes that are contained in the optional exclusion set.
436- /// </summary>
437- /// <typeparam name="T">The generic type of the source.</typeparam>
438- /// <param name="source">The source collection.</param>
439- /// <param name="exclusion">The optional values to exclude from selection.</param>
440- /// <returns>The value selected.</returns>
441- public static T RandomSelectOne < T > (
442- this ICollection < T > source ,
443- IEnumerable < T > exclusion = null )
444- {
445- if ( source . Count == 0 )
446- throw new InvalidOperationException ( "Source collection is empty." ) ;
447-
448- var index = RandomSelectIndex ( source , exclusion ) ;
449- if ( index == - 1 )
450- throw new InvalidOperationException ( "Exclusion set invalidates the source. No possible value can be selected." ) ;
451-
452- return source is IList < T > list
453- ? list [ index ]
454- : source . ElementAt ( index ) ;
455- }
456-
457- /// <summary>
458- /// Selects an index at random from the source and returns the value from it.
459- /// Will not select indexes that are contained in the optional exclusion set.
460- /// </summary>
461- /// <typeparam name="T">The generic type of the source.</typeparam>
462- /// <param name="source">The source array.</param>
463- /// <param name="exclusion">The optional values to exclude from selection.</param>
464- /// <returns>The value selected.</returns>
465- public static T RandomSelectOne < T > (
466- this T [ ] source ,
467- IEnumerable < T > exclusion = null )
468- {
469- if ( source . Length == 0 )
470- throw new InvalidOperationException ( "Source collection is empty." ) ;
471-
472- var index = RandomSelectIndex ( source , exclusion ) ;
473- if ( index == - 1 )
474- throw new InvalidOperationException ( "Exclusion set invalidates the source. No possible value can be selected." ) ;
475-
476- return source [ index ] ;
477- }
478-
479387 /// <summary>
480388 /// Attempts to select an index at random from the source and returns the value from it..
481389 /// Will not select indexes that are contained in the optional exclusion set.
@@ -504,60 +412,6 @@ public static bool TryRandomSelectOne<T>(
504412 return true ;
505413 }
506414
507- /// <summary>
508- /// Attempts to select an index at random from the source and returns the value from it..
509- /// Will not select indexes that are contained in the optional exclusion set.
510- /// </summary>
511- /// <typeparam name="T">The generic type of the source.</typeparam>
512- /// <param name="source">The source collection.</param>
513- /// <param name="value">The value selected.</param>
514- /// <param name="exclusion">The optional values to exclude from selection.</param>
515- /// <returns>True if a valid value was selected.</returns>
516- public static bool TryRandomSelectOne < T > (
517- this ICollection < T > source ,
518- out T value ,
519- IEnumerable < T > exclusion = null )
520- {
521- var index = RandomSelectIndex ( source , exclusion ) ;
522- if ( index == - 1 )
523- {
524- value = default ;
525- return false ;
526- }
527-
528- value = source is IList < T > list
529- ? list [ index ]
530- : source . ElementAt ( index ) ;
531-
532- return true ;
533- }
534-
535- /// <summary>
536- /// Attempts to select an index at random from the source and returns the value from it..
537- /// Will not select indexes that are contained in the optional exclusion set.
538- /// </summary>
539- /// <typeparam name="T">The generic type of the source.</typeparam>
540- /// <param name="source">The source array.</param>
541- /// <param name="value">The value selected.</param>
542- /// <param name="exclusion">The optional values to exclude from selection.</param>
543- /// <returns>True if a valid value was selected.</returns>
544- public static bool TryRandomSelectOne < T > (
545- this T [ ] source ,
546- out T value ,
547- IEnumerable < T > exclusion = null )
548- {
549- var index = RandomSelectIndex ( source , exclusion ) ;
550- if ( index == - 1 )
551- {
552- value = default ;
553- return false ;
554- }
555-
556- value = source [ index ] ;
557-
558- return true ;
559- }
560-
561415 /// <summary>
562416 /// Attempts to select an index at random from the source and returns the value from it..
563417 /// Will not select indexes that are contained in the optional exclusion set.
@@ -629,62 +483,6 @@ public static bool TryRandomSelectOneExcept<T>(
629483 return true ;
630484 }
631485
632- /// <summary>
633- /// Attempts to select an index at random from the source and returns the value from it..
634- /// Will not select indexes that are contained in the optional exclusion set.
635- /// </summary>
636- /// <typeparam name="T">The generic type of the source.</typeparam>
637- /// <param name="source">The source collection.</param>
638- /// <param name="value">The value selected.</param>
639- /// <param name="excluding">The value to exclude from selection.</param>
640- /// <param name="others">The additional set of optional values to exclude from selection.</param>
641- /// <returns>True if a valid value was selected.</returns>
642- public static bool TryRandomSelectOneExcept < T > (
643- this ICollection < T > source ,
644- out T value ,
645- T excluding , params T [ ] others )
646- {
647- var index = RandomSelectIndexExcept ( source , excluding , others ) ;
648- if ( index == - 1 )
649- {
650- value = default ;
651- return false ;
652- }
653-
654- value = source is IList < T > list
655- ? list [ index ]
656- : source . ElementAt ( index ) ;
657-
658- return true ;
659- }
660-
661- /// <summary>
662- /// Attempts to select an index at random from the source and returns the value from it..
663- /// Will not select indexes that are contained in the optional exclusion set.
664- /// </summary>
665- /// <typeparam name="T">The generic type of the source.</typeparam>
666- /// <param name="source">The source array.</param>
667- /// <param name="value">The value selected.</param>
668- /// <param name="excluding">The value to exclude from selection.</param>
669- /// <param name="others">The additional set of optional values to exclude from selection.</param>
670- /// <returns>True if a valid value was selected.</returns>
671- public static bool TryRandomSelectOneExcept < T > (
672- this T [ ] source ,
673- out T value ,
674- T excluding , params T [ ] others )
675- {
676- var index = RandomSelectIndexExcept ( source , excluding , others ) ;
677- if ( index == - 1 )
678- {
679- value = default ;
680- return false ;
681- }
682-
683- value = source [ index ] ;
684-
685- return true ;
686- }
687-
688486 /// <summary>
689487 /// Selects an index at random from the source and returns the value from it.
690488 /// Will not select indexes that are contained in the optional exclusion set.
@@ -743,50 +541,6 @@ public static T RandomSelectOneExcept<T>(
743541 throw new InvalidOperationException ( "Exclusion set invalidates the source. No possible value can be selected." ) ;
744542 }
745543
746- /// <summary>
747- /// Selects an index at random from the source and returns the value from it.
748- /// Will not select indexes that are contained in the optional exclusion set.
749- /// </summary>
750- /// <typeparam name="T">The generic type of the source.</typeparam>
751- /// <param name="source">The source collection.</param>
752- /// <param name="excluding">The value to exclude from selection.</param>
753- /// <param name="others">The additional set of optional values to exclude from selection.</param>
754- /// <returns>The value selected.</returns>
755- public static T RandomSelectOneExcept < T > (
756- this ICollection < T > source ,
757- T excluding , params T [ ] others )
758- {
759- if ( source . Count == 0 )
760- throw new InvalidOperationException ( "Source collection is empty." ) ;
761-
762- if ( source . TryRandomSelectOneExcept ( out T value , excluding , others ) )
763- return value ;
764-
765- throw new InvalidOperationException ( "Exclusion set invalidates the source. No possible value can be selected." ) ;
766- }
767-
768- /// <summary>
769- /// Selects an index at random from the source and returns the value from it.
770- /// Will not select indexes that are contained in the optional exclusion set.
771- /// </summary>
772- /// <typeparam name="T">The generic type of the source.</typeparam>
773- /// <param name="source">The source array.</param>
774- /// <param name="excluding">The value to exclude from selection.</param>
775- /// <param name="others">The additional set of optional values to exclude from selection.</param>
776- /// <returns>The value selected.</returns>
777- public static T RandomSelectOneExcept < T > (
778- this T [ ] source ,
779- T excluding , params T [ ] others )
780- {
781- if ( source . Length == 0 )
782- throw new InvalidOperationException ( "Source array is empty." ) ;
783-
784- if ( source . TryRandomSelectOneExcept ( out T value , excluding , others ) )
785- return value ;
786-
787- throw new InvalidOperationException ( "Exclusion set invalidates the source. No possible value can be selected." ) ;
788- }
789-
790544 /// <summary>
791545 /// Select a random number except the excluded ones.
792546 /// </summary>
0 commit comments