This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Common.cs
52 lines (46 loc) · 1.51 KB
/
Common.cs
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
namespace EnemyGenerator
{
/// This class holds the project common functions and constants.
public class Common
{
/// Unknown reference.
public static readonly int UNKNOWN = -1;
/// Return a random integer percentage (from 0 to 99, 100 numbers).
public static int RandomPercent(
ref Random _rand
) {
return _rand.Next(100);
}
/// Return a random integer number from the entered inclusive range.
public static int RandomInt(
(int min, int max) _range,
ref Random _rand
) {
return _rand.Next(_range.min, _range.max + 1);
}
/// Return a random float number from the entered inclusive range.
public static float RandomFloat(
(float min, float max) _range,
ref Random _rand
) {
double n = _rand.NextDouble();
return (float) (n * (_range.max - _range.min) + _range.min);
}
/// Return a random element from the entered array.
public static T RandomElementFromArray<T>(
T[] _range,
ref Random _rand
) {
return _range[_rand.Next(0, _range.Length)];
}
/// Return a random element from the entered list.
public static T RandomElementFromList<T>(
List<T> _range,
ref Random _rand
) {
return _range[_rand.Next(0, _range.Count)];
}
}
}