This repository has been archived by the owner on Apr 18, 2024. It is now read-only.
RandomExtentions
Stone_Red edited this page May 20, 2022
·
4 revisions
-
NextItem
-
Description: Returns an random item from the specified collection using the Random class
-
Parameters:
this Random random
,IEnumerable<T> collection
-
Example usage:
string[] arr = { "test1", "test2", "test3" }; Random rnd = new Random(); string randomItem = rnd.NextItem(arr); Console.WriteLine(randomItem);
-
Output (Will be random every time):
test2
-
-
NextBool
-
Description: Returns a random bool using the "Random" class
-
Parameters:
this Random random
-
Example usage:
Random rnd = new Random(); string randomBool = rnd.NextBool(); Console.WriteLine(randomBool);
-
Output (Will be random every time):
true
-
-
NextEnum<T>
-
Description: Returns a random bool using the "Random" class
-
Parameters:
this Random random
,Enum
-
Example usage:
private enum MyEnum { a, b, c } ... Random rnd = new Random(); MyEnum randomEnum = rnd.NextEnum(new MyEnum()); Console.WriteLine(randomEnum);
-
Output (Will be random every time):
c
-