diff --git a/OpenRA.FileFormats/Exts.cs b/OpenRA.FileFormats/Exts.cs index af2e5d98ef..30a629c59d 100755 --- a/OpenRA.FileFormats/Exts.cs +++ b/OpenRA.FileFormats/Exts.cs @@ -110,6 +110,14 @@ namespace OpenRA return xs[r.Next(xs.Length)]; } + public static T RandomOrDefault(this IEnumerable ts, Thirdparty.Random r) + { + if (!ts.Any()) + return default(T); + + return ts.Random(r); + } + public static float Product(this IEnumerable xs) { return xs.Aggregate(1f, (a, x) => a * x);