Repository navigation
Expand file tree
/
Copy pathRandomizer.cs
More file actions
101 lines (84 loc) · 3.43 KB
/
Copy pathRandomizer.cs
File metadata and controls
101 lines (84 loc) · 3.43 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Text;
namespace Process.NET.Utilities
{
/// <summary>
/// Static helper class providing tools for generating random numbers or strings.
/// </summary>
public static class Randomizer
{
#region GenerateString
/// <summary>
/// Returns a random string where its size is within a specified range.
/// </summary>
/// <param name="minSize">The inclusive lower bound of the size of the string returned.</param>
/// <param name="maxSize">The exclusive upper bound of the size of the string returned.</param>
/// <returns></returns>
public static string GenerateString(int minSize = 40, int maxSize = 40)
{
// Create the string builder with a specific capacity
var builder = new StringBuilder(GenerateNumber(minSize, maxSize));
// Fill the string builder
for (var i = 0; i < builder.Capacity; i++)
builder.Append(AllowedChars[GenerateNumber(AllowedChars.Length - 1)]);
return builder.ToString();
}
#endregion
#region GenerateGuid
/// <summary>
/// Initializes a new instance of the <see cref="Guid" /> structure.
/// </summary>
/// <returns>A new <see cref="Guid" /> object.</returns>
public static Guid GenerateGuid()
{
return Guid.NewGuid();
}
#endregion
#region Fields
/// <summary>
/// Provides random engine.
/// </summary>
private static readonly Random Random = new Random();
/// <summary>
/// Allowed characters in random strings.
/// </summary>
private static readonly char[] AllowedChars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".ToCharArray();
#endregion
#region GenerateNumber
/// <summary>
/// Returns a random number within a specified range.
/// </summary>
/// <param name="minValue">The inclusive lower bound of the random number returned.</param>
/// <param name="maxValue">
/// The exclusive upper bound of the random number returned. maxValue must be greater than or equal
/// to minValue.
/// </param>
/// <returns>A 32-bit signed integer greater than or equal to minValue and less than maxValue.</returns>
public static int GenerateNumber(int minValue, int maxValue)
{
return Random.Next(minValue, maxValue);
}
/// <summary>
/// Returns a nonnegative random number less than the specified maximum.
/// </summary>
/// <param name="maxValue">
/// The exclusive upper bound of the random number to be generated. maxValue must be greater than or
/// equal to zero.
/// </param>
/// <returns>A 32-bit signed integer greater than or equal to zero, and less than maxValue.</returns>
public static int GenerateNumber(int maxValue)
{
return Random.Next(maxValue);
}
/// <summary>
/// Returns a nonnegative random number.
/// </summary>
/// <returns>A 32-bit signed integer greater than or equal to zero and less than <see cref="int.MaxValue" />.</returns>
public static int GenerateNumber()
{
return Random.Next();
}
#endregion
}
}