-
Notifications
You must be signed in to change notification settings - Fork 0
/
RNG.cs
52 lines (39 loc) · 1.34 KB
/
RNG.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 Microsoft.Xna.Framework;
using MonoGame.Extended;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StereoGame
{
public static class RNG
{
private static Random rng;
public static Random Rng
{
get => rng ?? (rng = new Random());
}
/// <param name="min">Inclusive lower bound</param>
/// <param name="max">Exclusive upper bound</param>
public static int NextInt(int min, int max)
=> Rng.Next(min, max);
public static double NextDouble()
=> Rng.NextDouble();
public static double NextDouble(double max)
=> NextDouble() * max;
public static double NextDouble(double min, double max)
=> NextDouble(max-min) + min;
public static float NextFloat()
=> (float)Rng.NextDouble();
public static float NextFloat(float max)
=> NextFloat() * max;
public static float NextFloat(float min, float max)
=> NextFloat(max - min) + min;
public static Vector2 RandomPos(ref Vector2 topLeft, ref Vector2 bottomRight)
=> new Vector2(NextFloat(topLeft.X, bottomRight.X), NextFloat(topLeft.Y, bottomRight.Y));
public static Vector2 RandomPos(ref RectangleF area)
=> new Vector2(NextFloat(area.Left, area.Right), NextFloat(area.Top, area.Bottom));
}
}