1: public class Random:System.Random
2: {
3: /// <summary>
4: /// Returns a random boolean value
5: /// </summary>
6: /// <returns>returns a boolean</returns>
7: public bool NextBool()
8: {
9: if (Next(0, 2) == 1)
10: return true;
11: return false;
12: }
13:
14: /// <summary>
15: /// Gets a random enum value
16: /// </summary>
17: /// <typeparam name="T">The enum type</typeparam>
18: /// <returns>A random value from an enum</returns>
19: public T NextEnum<T>()
20: {
21: Array Values = Enum.GetValues(typeof(T));
22: int Index = Next(0, Values.Length);
23: return (T)Values.GetValue(Index);
24: }
25:
26: /// <summary>
27: /// Randomly generates a new time span
28: /// </summary>
29: /// <param name="Start">Start time span</param>
30: /// <param name="End">End time span</param>
31: /// <returns>A time span between the start and end</returns>
32: public TimeSpan NextTimeSpan(TimeSpan Start, TimeSpan End)
33: {
34: if (Start > End)
35: {
36: throw new ArgumentException("The start value must be earlier than the end value");
37: }
38: return Start + new TimeSpan((long)(new TimeSpan(End.Ticks - Start.Ticks).Ticks * NextDouble()));
39: }
40:
41: /// <summary>
42: /// Returns a random color
43: /// </summary>
44: /// <returns>A random color between black and white</returns>
45: public Color NextColor()
46: {
47: return NextColor(Color.Black, Color.White);
48: }
49:
50: /// <summary>
51: /// Returns a random color within a range
52: /// </summary>
53: /// <param name="MinColor">The inclusive minimum color (minimum for A, R, G, and B values)</param>
54: /// <param name="MaxColor">The inclusive maximum color (max for A, R, G, and B values)</param>
55: /// <returns>A random color between the min and max values</returns>
56: public Color NextColor(Color MinColor, Color MaxColor)
57: {
58: return Color.FromArgb(Next(MinColor.A, MaxColor.A + 1),
59: Next(MinColor.R, MaxColor.R + 1),
60: Next(MinColor.G, MaxColor.G + 1),
61: Next(MinColor.B, MaxColor.B + 1));
62: }
63: }