-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cs
More file actions
37 lines (30 loc) · 698 Bytes
/
Utils.cs
File metadata and controls
37 lines (30 loc) · 698 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Collections.Generic;
namespace PopulationGenerator
{
public static class Utils
{
public static Random Rnd = new Random();
public static T Pick<T>(params T[] args)
{
return args[Rnd.Next(args.Length)];
}
public static T Pick<T>() where T : struct
{
var values = Enum.GetValues(typeof(T));
return (T)values.GetValue(Rnd.Next(values.Length));
}
public static T Pick<T>(this List<T> list)
{
return list[Rnd.Next(list.Count)];
}
public static T Clamp<T>(T value, T min, T max) where T : IComparable<T>
{
if (value.CompareTo(min) < 0)
return min;
if (value.CompareTo(max) > 0)
return max;
return value;
}
}
}