Skip to content

Instantly share code, notes, and snippets.

@aruss
Created August 18, 2016 07:43
Show Gist options
  • Save aruss/0e87ad82af0a0df5850626dc7c720b46 to your computer and use it in GitHub Desktop.
Save aruss/0e87ad82af0a0df5850626dc7c720b46 to your computer and use it in GitHub Desktop.
public static class RandomUtils
{
private static string[] Lorem = new[] { "lorem", "ipsum", "dolor", "sit", "amet", "consectetuer", "adipiscing", "elit", "sed", "diam", "nonummy", "nibh", "euismod", "tincidunt", "ut", "laoreet", "dolore", "magna", "aliquam", "erat" };
public static Random Rand = new Random();
public static string Words(int max, int min = 1)
{
var words = new List<string>();
for (int i = min; i <= max; i++)
{
words.Add(Lorem[Rand.Next(Lorem.Length)]);
}
return String.Join(" ", words);
}
public static string Sentenses(int count = 1, int max = 6, int min = 4)
{
var sentenses = new List<string>();
for (int i = 0; i < count; i++)
{
sentenses.Add(String.Format("{0}.", RandomUtils.Words(max, min).FirstCharToUpper()));
}
return String.Join(" ", sentenses);
}
public static T Random<T>(this IEnumerable<T> items)
{
if (items.Count() == 0)
{
return default(T);
}
return items.ElementAt(Rand.Next(items.Count()));
}
public static string FirstCharToUpper(this string str)
{
return String.Format("{0}{1}", str[0].ToString().ToUpper(), str.Substring(1));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment