-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiscelHelperClass.cs
More file actions
74 lines (63 loc) · 1.36 KB
/
MiscelHelperClass.cs
File metadata and controls
74 lines (63 loc) · 1.36 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
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace Algorithms
{
public class MiscelHelperClass
{
public static int[] RandomGenerateIntArray(int length)
{
int maxVal = 20;
return RandomGenerateIntArray(length, maxVal);
}
public static int[] RandomGenerateIntArray(int length, int maxVal)
{
int[] newArray = new int[length];
Random a = new Random();
for (int i = 0; i < length; i++)
{
int n = a.Next(maxVal);
newArray[i] = n;
}
return newArray;
}
public static int[] RandomGenUniqueIntArray(int length)
{
int maxVal = 30;
int[] newArray = new int[length];
ArrayList existingNum = new ArrayList();
Random a = new Random();
int i = 0;
while (i < length)
{
int n = a.Next(maxVal);
if (existingNum.Contains(n) == false)
{
existingNum.Add(n);
newArray[i] = n;
i++;
}
}
return newArray;
}
public static int[] GenOrderedIntArray(int length, int startingVal, int increment)
{
int[] newArray = new int[length];
for (int i = 0; i < length; i++)
{
newArray[i] = startingVal + i * increment;
}
return newArray;
}
public static string PrintArray(int[] arr)
{
string msg ="";
for (int i = 0; i < arr.Length; i++)
{
msg = msg + arr[i].ToString() + "\t";
}
return msg;
}
}
}