From d35d875897f8498cab6db16cc3808319d8b62ff7 Mon Sep 17 00:00:00 2001 From: Diamond-Wolf Date: Tue, 10 Aug 2021 13:01:47 -0600 Subject: [PATCH 1/2] Add params variant of Choose() Added a new variant of Choose() which allows an arbitrary number of arguments. --- Nez.Portable/Math/Random.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Nez.Portable/Math/Random.cs b/Nez.Portable/Math/Random.cs index 7f37b5d1f..669444e73 100644 --- a/Nez.Portable/Math/Random.cs +++ b/Nez.Portable/Math/Random.cs @@ -218,5 +218,15 @@ public static T Choose(T first, T second, T third, T fourth) return fourth; } } + + + /// + /// randomly returns one of the given values + /// + /// The 1st type parameter. + public static T Choose(params T[] options) + { + return options[Nez.Random.NextInt(options.Length)]; + } } -} \ No newline at end of file +} From 00670024af0ad61ec01c34cb9cfd52f0cb6b0d31 Mon Sep 17 00:00:00 2001 From: Diamond-Wolf Date: Tue, 10 Aug 2021 14:19:32 -0600 Subject: [PATCH 2/2] Remove unnecessary specification of NextInt from Choose Remove Nez.Random specification of NextInt() call, since it's being called from within Nez.Random --- Nez.Portable/Math/Random.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Nez.Portable/Math/Random.cs b/Nez.Portable/Math/Random.cs index 669444e73..80b0deaee 100644 --- a/Nez.Portable/Math/Random.cs +++ b/Nez.Portable/Math/Random.cs @@ -226,7 +226,7 @@ public static T Choose(T first, T second, T third, T fourth) /// The 1st type parameter. public static T Choose(params T[] options) { - return options[Nez.Random.NextInt(options.Length)]; + return options[NextInt(options.Length)]; } } }