forked from Elfocrash/L2dotNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRnd.cs
More file actions
60 lines (49 loc) · 1.35 KB
/
Copy pathRnd.cs
File metadata and controls
60 lines (49 loc) · 1.35 KB
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
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Linq;
namespace L2dotNET.Utility.Geometry
{
public static class Rnd
{
//TODO: RandomThreadSafe.Instance
private static readonly Random rnd = new Random();
public static double Get()
{
return rnd.NextDouble();
}
public static int Get(int a)
{
return (int)(rnd.NextDouble() * a);
}
public static int Get(int min, int max)
{
return min + (int)Math.Floor(rnd.NextDouble() * ((max - min) + 1));
}
public static int NextInt(int n)
{
return (int)Math.Floor(rnd.NextDouble() * n);
}
public static int NextInt()
{
return rnd.Next();
}
public static double NextDouble()
{
return rnd.NextDouble();
}
public static bool NextBoolean()
{
return Convert.ToBoolean(rnd.Next());
}
public static IEnumerable<T> Get<T>(List<T> list)
{
if ((list == null) || (list.Count == 0))
return null;
return list.Shuffle().Take(list.Count);
}
public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source)
{
return source.OrderBy(x => Guid.NewGuid());
}
}
}