@robloxyoutube73/

Username Generator

C#

Made for my sister, as she's having a hard time thinking of a username for stuff. But anybody can use it if they'd like.

fork
loading
Files
  • main.cs
  • Adjectives
  • main.exe
  • Nouns
  • Verbs
main.cs
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using System;
using System.IO;

class MainClass {
	//create a Random for random numbers
  private static Random random = new Random();
	
  public static void Main (string[] args) {
    //get the base file path
    string basePath = Directory.GetCurrentDirectory();
    
    //get the answers for the nouns, verbs and adjectives
    //Path.Combine correctly create the path so we don't have to worry about it as much
    string[] nouns = GetAnswers(Path.Combine(basePath, "Nouns"));
    string[] verbs = GetAnswers(Path.Combine(basePath, "Verbs"));
    string[] adjs = GetAnswers(Path.Combine(basePath, "Adjectives"));
    
    do{
    	//generate _ usernames with the answers and given amount
    	GenerateUsernames(nouns, verbs, adjs, 25);
    	
    	//ask to make more
    	Console.WriteLine("\n\tPress Enter to generate more usernames, or press another key and enter to end.");
    }while(Console.ReadLine() == "");
  }
  
  //generates and displays the usernames
  private static void GenerateUsernames(string[] nouns, string[] verbs, string[] adjs, int amount){
  	//make a space
  	Console.WriteLine("\n----------\n\n");
  	
  	//repeat for the amount
  	for(int i = 0; i < amount; i++){
  		//determine which way to organize words based on the number generated
	  	switch(random.Next(5)){
	  		case 0://adjective noun
	  			GenerateUsername(new string[]{
	  				GetWord(adjs),
	  				GetWord(nouns)
	  			});
	  			break;
	  		case 1://adjective verb
	  			GenerateUsername(new string[] {
	  				GetWord(adjs),
	  				GetWord(verbs)
	  			});
	  			break;
	  		case 2://verb noun verb
	  			GenerateUsername(new string[]{
	  				GetWord(verbs),
	  				GetWord(nouns),
	  				GetWord(verbs)
	  			});
	  			break;
	  		case 3://The adjective noun
	  			GenerateUsername(new string[]{
	  				"The",
	  				GetWord(adjs),
	  				GetWord(nouns)
	  			});
	  			break;
	  		case 4://adjective adjective noun
	  			GenerateUsername(new string[]{
	  				GetWord(adjs),
	  				GetWord(adjs),
	  				GetWord(nouns)
	  			});
	  			break;
	  	}
  	}
  }
  
  //gets a random item from the array
  private static string GetWord(string[] words){
  	//return nothing if theres no words
  	if(words.Length == 0) return "";
  	
  	//return a random word
  	return words[random.Next(words.Length)];
  }
  
  //generates an individual username and prints it
  private static void GenerateUsername(string[] words){
  	//add all the words together into one string
  	string username = "";
  	
  	foreach(string word in words){
  		username += word;
  	}
  	
  	//print it
  	Console.WriteLine(username);
  }
  
  //gets all of the answers from a file with questions
  private static string[] GetAnswers(string path){
  	
  	//get all the lines from the file
  	string[] lines = File.ReadAllLines(path);
  	
  	//check lines to make sure things can be asked
  	if(lines.Length <= 1){
  		//there's either no or only one line, no questions
  		return new string[0];
  	}
  	
  	//the first is the directions, print directions
  	Console.WriteLine("\n" + lines[0]);
  	
  	//create an array with same space - 1, because we no longer need the directions
  	string[] answers = new string[lines.Length - 1];
  	
  	//cycle through the questions and get the answers
  	for(int i = 0; i < lines.Length - 1; i++){
  		answers[i] = GetAnswer(lines[i + 1]);
  	}
  	
  	//return the answers
  	return answers;
  }
  
  //gets an individual answer
  private static string GetAnswer(string prompt){
  	//check if there is a prompt
  	if(!string.IsNullOrEmpty(prompt)){
  		//there is a prompt, print it
  		Console.Write(prompt + ": ");
  		//use Write and not WriteLine so the answer is on the same line as the question
  	}
  	
  	//get the answer, as long as it is not blank
  	string answer = "";
  	do{
  		//get answer and remove spaces
  		answer = Console.ReadLine().Replace(" ", string.Empty);
  	} while(string.IsNullOrEmpty(answer));
  	
  	//user gave valid answer, return it
  	return answer;
  }
}