mirror of
https://github.com/Stone-Red-Code/Stone_Red-C-Sharp-Utilities.git
synced 2026-09-09 09:55:59 +02:00
Created RandomExtentions (markdown)
@@ -0,0 +1,65 @@
|
|||||||
|
### Stone_Red_Utilities.RandomExtentions
|
||||||
|
|
||||||
|
#### Methods
|
||||||
|
|
||||||
|
* NextItem
|
||||||
|
* Description: Returns an random item from the specified collection using the Random class
|
||||||
|
* Parameters: `this Random random`, `IEnumerable<T> collection`
|
||||||
|
* Example usage:
|
||||||
|
|
||||||
|
```cs
|
||||||
|
string[] arr = { "test1", "test2", "test3" };
|
||||||
|
Random rnd = new Random();
|
||||||
|
string randomItem = rnd.NextItem(arr);
|
||||||
|
Console.WriteLine(randomItem);
|
||||||
|
```
|
||||||
|
|
||||||
|
* Output (Will be random every time):
|
||||||
|
|
||||||
|
```text
|
||||||
|
test2
|
||||||
|
```
|
||||||
|
|
||||||
|
* NextBool
|
||||||
|
* Description: Returns a random bool using the "Random" class
|
||||||
|
* Parameters: `this Random random`, `IEnumerable<T> collection`
|
||||||
|
* Example usage:
|
||||||
|
|
||||||
|
```cs
|
||||||
|
string[] arr = { "test1", "test2", "test3" };
|
||||||
|
Random rnd = new Random();
|
||||||
|
string randomItem = rnd.NextItem(arr);
|
||||||
|
Console.WriteLine(randomItem);
|
||||||
|
```
|
||||||
|
|
||||||
|
* Output (Will be random every time):
|
||||||
|
|
||||||
|
```text
|
||||||
|
test2
|
||||||
|
```
|
||||||
|
|
||||||
|
* NextEnum\<T>
|
||||||
|
* Description: Returns a random bool using the "Random" class
|
||||||
|
* Parameters: `this Random random`, `IEnumerable<T> collection`
|
||||||
|
* Example usage:
|
||||||
|
|
||||||
|
```cs
|
||||||
|
private enum MyEnum
|
||||||
|
{
|
||||||
|
a,
|
||||||
|
b,
|
||||||
|
c
|
||||||
|
}
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
Random rnd = new Random();
|
||||||
|
MyEnum randomItem = rnd.NextEnum(new MyEnum());
|
||||||
|
Console.WriteLine(randomItem);
|
||||||
|
```
|
||||||
|
|
||||||
|
* Output (Will be random every time):
|
||||||
|
|
||||||
|
```text
|
||||||
|
c
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user