Skip to content

Instantly share code, notes, and snippets.

@money4honey
Created August 6, 2015 18:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save money4honey/5a6eec31193c4779066d to your computer and use it in GitHub Desktop.
Save money4honey/5a6eec31193c4779066d to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace myClasses
{
public class RandomMaster
{
static Random random = new Random();
static string[] numbers = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
static string[] alphabet = { "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 bool randomBool(int chance, int max)
{
int rNum = random.Next(max);
if (rNum <= chance) return true;
else return false;
}
public static string randomString(int length) {
string randomString = "";
for (int i = 0; i < length; i++ ) {
if (randomBool(50, 100)) {
if (randomBool(50, 100)) { randomString += alphabet[random.Next(alphabet.Length)]; }
else { randomString += alphabet[random.Next(alphabet.Length)].ToUpper(); }
}
else {
randomString += numbers[random.Next(numbers.Length)];
}
}
return randomString;
}
public static string randomStringLetters(int length)
{
string randomString = "";
for (int i = 0; i < length; i++)
{
if (randomBool(50, 100))
{
if (randomBool(50, 100)) { randomString += alphabet[random.Next(alphabet.Length)]; }
else { randomString += alphabet[random.Next(alphabet.Length)].ToUpper(); }
}
}
return randomString;
}
public static string randomStringNumbers(int length)
{
string randomString = "";
for (int i = 0; i < length; i++)
{
randomString += numbers[random.Next(numbers.Length)];
}
return randomString;
}
public static int randomRange(int min, int max) {
return random.Next(min, max);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment