summaryrefslogtreecommitdiff
path: root/Plugins/MonoGame.Extended/source/MonoGame.Extended/Math/RandomExtensions.cs
blob: 14abb5dafa82fc4a6f8bfad328fb1d7d7b9b05d5 (plain)
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
using System;
using Microsoft.Xna.Framework;

namespace MonoGame.Extended
{
    public static class RandomExtensions
    {
        public static int Next(this Random random, Range<int> range)
        {
            return random.Next(range.Min, range.Max);
        }

        public static float NextSingle(this Random random, float min, float max)
        {
            return (max - min)*NextSingle(random) + min;
        }

        public static float NextSingle(this Random random, float max)
        {
            return max*NextSingle(random);
        }

        public static float NextSingle(this Random random)
        {
            return (float) random.NextDouble();
        }

        public static float NextSingle(this Random random, Range<float> range)
        {
            return NextSingle(random, range.Min, range.Max);
        }

        public static float NextAngle(this Random random)
        {
            return NextSingle(random, -MathHelper.Pi, MathHelper.Pi);
        }

        public static void NextUnitVector(this Random random, out Vector2 vector)
        {
            var angle = NextAngle(random);
            vector = new Vector2((float) Math.Cos(angle), (float) Math.Sin(angle));
        }
    }
}