-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomURL.cs
More file actions
40 lines (36 loc) · 1.37 KB
/
RandomURL.cs
File metadata and controls
40 lines (36 loc) · 1.37 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
//chnaged through visual studio 2017
// Required namespaces
using System;
using System.Collections.Generic;
using System.Web;
/// <summary>
/// RandomURL class generates Random URLs for applications.
/// </summary>
public class RandomURL
{
// List of characters and numbers to be used...
private static List<int> numbers = new List<int>() {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
private static List<char> characters = new List<char>()
{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B',
'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '-', '_'};
public static string GetURL () {
string URL = "";
Random rand = new Random();
// run the loop till I get a string of 10 characters
for (int i = 0; i < 11; i++) {
// Get random numbers, to get either a character or a number...
int random = rand.Next(0, 3);
if(random == 1) {
// use a number
random = rand.Next(0, numbers.Count);
URL += numbers[random].ToString();
} else {
random = rand.Next(0, characters.Count);
URL += characters[random].ToString();
}
}
return URL;
}
}