-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandom.cs
More file actions
56 lines (55 loc) · 1.58 KB
/
Random.cs
File metadata and controls
56 lines (55 loc) · 1.58 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
namespace RandomCS
{
class Random
{
public double random_value;
public Random()
{
this.Randomize();
}
public double Randomize()
{
this.random_value = new System.Random().NextDouble();
return this.random_value;
}
public double getValue()
{
return this.random_value;
}
public double Range(double min = 0.0, double max = 1.0)
{
return min + (this.random_value * (max - min));
}
public int iRange(int min = 0, int max = 1)
{
return (int)(this.Range(min, max));
}
public string Choice(System.Array array)
{
return array.GetValue(this.iRange(0, array.Length)).ToString();
}
public System.Array Choices(System.Array array, int length)
{
string[] rarray = new string[length];
for (int i=0; i < length ;i++)
{
rarray[i] = this.Choice(array);
this.Randomize();
}
return rarray;
}
protected string ConvertArrayToString(System.Array array)
{
string _str = "";
foreach (string arr in array)
{
_str += arr;
}
return _str;
}
public string StringRange(int length, string addchars = "")
{
return this.ConvertArrayToString(this.Choices(("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"+addchars).ToCharArray(), length));
}
}
}