Renamed PickRandom to SelectRandom

This commit is contained in:
hondacrx
2017-06-21 11:57:04 -04:00
parent d16d6d57f0
commit 430507a10a
28 changed files with 54 additions and 53 deletions
+11 -10
View File
@@ -80,16 +80,6 @@ namespace System.Collections.Generic
collection.RemoveAll(check.Invoke);
}
public static T PickRandom<T>(this IEnumerable<T> source)
{
return source.PickRandom(1).Single();
}
public static IEnumerable<T> PickRandom<T>(this IEnumerable<T> source, uint count)
{
return source.Shuffle().Take((int)count);
}
public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source)
{
return source.OrderBy(x => Guid.NewGuid());
@@ -136,6 +126,17 @@ namespace System.Collections.Generic
list = listCopy;
}
public static T SelectRandom<T>(this IEnumerable<T> source)
{
return source.SelectRandom(1).Single();
}
public static IEnumerable<T> SelectRandom<T>(this IEnumerable<T> source, uint count)
{
return source.Shuffle().Take((int)count);
}
public static T SelectRandomElementByWeight<T>(this IEnumerable<T> sequence, Func<T, float> weightSelector)
{
float totalWeight = sequence.Sum(weightSelector);