Unstable v0.1300.0.0 (February 19th 2021)

This commit is contained in:
Joonas Rikkonen
2021-02-25 13:44:23 +02:00
parent b772654326
commit 24cbef485a
441 changed files with 21343 additions and 8562 deletions
@@ -49,6 +49,19 @@ namespace Barotrauma.Extensions
return count == 0 ? default : source.ElementAt(Rand.Range(0, count, randSync));
}
}
public static T GetRandom<T>(this IEnumerable<T> source, Random random)
{
if (source is IList<T> list)
{
int count = list.Count;
return count == 0 ? default : list[random.Next(0, count)];
}
else
{
int count = source.Count();
return count == 0 ? default : source.ElementAt(random.Next(0, count));
}
}
public static T RandomElementByWeight<T>(this IEnumerable<T> source, Func<T, float> weightSelector, Rand.RandSync randSync = Rand.RandSync.Unsynced)
{