diff --git a/Lorem.NET/Lorem.cs b/Lorem.NET/Lorem.cs index d09f577..f9d612f 100644 --- a/Lorem.NET/Lorem.cs +++ b/Lorem.NET/Lorem.cs @@ -4,146 +4,156 @@ using System.Linq; namespace LoremNET { - public partial class Lorem - { - public static bool Chance(int successes, int attempts) - { - var number = Number(1, attempts); + public partial class Lorem + { + public static bool Chance(int successes, int attempts) + { + var number = Number(1, attempts); - return number <= successes; - } + return number <= successes; + } - public static T Random(T[] items) - { - var index = RandomHelper.Instance.Next(items.Length); + public static T Random(T[] items) + { + var index = RandomHelper.Instance.Next(items.Length); - return items[index]; - } + return items[index]; + } - /* http://stackoverflow.com/a/6651661/234132 */ - public static long Number(long min, long max) - { - byte[] buf = new byte[8]; - RandomHelper.Instance.NextBytes(buf); - long longRand = BitConverter.ToInt64(buf, 0); + public static TEnum RandomEnum() + { + if (typeof(TEnum).IsEnum) + { + var v = Enum.GetValues(typeof(TEnum)); + return (TEnum)v.GetValue(LoremNET.RandomHelper.Instance.Next(v.Length)); + } + else throw new ArgumentException("Generic type must be an enum."); + } - return (Math.Abs(longRand % ((max + 1) - min)) + min); - } + /* http://stackoverflow.com/a/6651661/234132 */ + public static long Number(long min, long max) + { + byte[] buf = new byte[8]; + RandomHelper.Instance.NextBytes(buf); + long longRand = BitConverter.ToInt64(buf, 0); - #region DateTime + return (Math.Abs(longRand % ((max + 1) - min)) + min); + } - public static DateTime DateTime(int startYear = 1950, int startMonth = 1, int startDay = 1) - { - return DateTime(new System.DateTime(startYear, startMonth, startDay), System.DateTime.Now); - } + #region DateTime - public static DateTime DateTime(DateTime min) - { - return DateTime(min, System.DateTime.Now); - } + public static DateTime DateTime(int startYear = 1950, int startMonth = 1, int startDay = 1) + { + return DateTime(new System.DateTime(startYear, startMonth, startDay), System.DateTime.Now); + } - /* http://stackoverflow.com/a/1483677/234132 */ - public static DateTime DateTime(DateTime min, DateTime max) - { - TimeSpan timeSpan = max - min; - TimeSpan newSpan = new TimeSpan(0, RandomHelper.Instance.Next(0, (int)timeSpan.TotalMinutes), 0); - - return min + newSpan; - } + public static DateTime DateTime(DateTime min) + { + return DateTime(min, System.DateTime.Now); + } - #endregion + /* http://stackoverflow.com/a/1483677/234132 */ + public static DateTime DateTime(DateTime min, DateTime max) + { + TimeSpan timeSpan = max - min; + TimeSpan newSpan = new TimeSpan(0, RandomHelper.Instance.Next(0, (int)timeSpan.TotalMinutes), 0); - #region Text + return min + newSpan; + } - public static string Email() - { - return string.Format("{0}@{1}.com", Lorem.Words(1, false), Lorem.Words(1, false)); - } + #endregion - public static string Words(int wordCount, bool uppercaseFirstLetter = true, bool includePunctuation = false) - { - return Words(wordCount, wordCount, uppercaseFirstLetter, includePunctuation); - } + #region Text - public static string Words(int wordCountMin, int wordCountMax, bool uppercaseFirstLetter = true, bool includePunctuation = false) - { - var source = string.Join(" ", Source.WordList(includePunctuation).Take(RandomHelper.Instance.Next(wordCountMin, wordCountMax))); + public static string Email() + { + return string.Format("{0}@{1}.com", Lorem.Words(1, false), Lorem.Words(1, false)); + } - if (uppercaseFirstLetter) - { - source = source.UppercaseFirst(); - } + public static string Words(int wordCount, bool uppercaseFirstLetter = true, bool includePunctuation = false) + { + return Words(wordCount, wordCount, uppercaseFirstLetter, includePunctuation); + } - return source; - } + public static string Words(int wordCountMin, int wordCountMax, bool uppercaseFirstLetter = true, bool includePunctuation = false) + { + var source = string.Join(" ", Source.WordList(includePunctuation).Take(RandomHelper.Instance.Next(wordCountMin, wordCountMax))); - public static string Sentence(int wordCount) - { - return Sentence(wordCount, wordCount); - } + if (uppercaseFirstLetter) + { + source = source.UppercaseFirst(); + } - public static string Sentence(int wordCountMin, int wordCountMax) - { - return string.Format("{0}.", Words(wordCountMin, wordCountMax, true, true)).Replace(",.", ".").Remove(".."); - } + return source; + } - public static string Paragraph(int wordCount, int sentenceCount) - { - return Paragraph(wordCount, wordCount, sentenceCount, sentenceCount); - } + public static string Sentence(int wordCount) + { + return Sentence(wordCount, wordCount); + } - public static string Paragraph(int wordCountMin, int wordCountMax, int sentenceCount) - { - return Paragraph(wordCountMin, wordCountMax, sentenceCount, sentenceCount); - } + public static string Sentence(int wordCountMin, int wordCountMax) + { + return string.Format("{0}.", Words(wordCountMin, wordCountMax, true, true)).Replace(",.", ".").Remove(".."); + } - public static string Paragraph(int wordCountMin, int wordCountMax, int sentenceCountMin, int sentenceCountMax) - { - var source = string.Join(" ", Enumerable.Range(0, RandomHelper.Instance.Next(sentenceCountMin, sentenceCountMax)).Select(x => Sentence(wordCountMin, wordCountMax))); + public static string Paragraph(int wordCount, int sentenceCount) + { + return Paragraph(wordCount, wordCount, sentenceCount, sentenceCount); + } - //remove traililng space - return source.Remove(source.Length - 1); - } + public static string Paragraph(int wordCountMin, int wordCountMax, int sentenceCount) + { + return Paragraph(wordCountMin, wordCountMax, sentenceCount, sentenceCount); + } - public static IEnumerable Paragraphs(int wordCount, int sentenceCount, int paragraphCount) - { - return Paragraphs(wordCount, wordCount, sentenceCount, sentenceCount, paragraphCount, paragraphCount); - } + public static string Paragraph(int wordCountMin, int wordCountMax, int sentenceCountMin, int sentenceCountMax) + { + var source = string.Join(" ", Enumerable.Range(0, RandomHelper.Instance.Next(sentenceCountMin, sentenceCountMax)).Select(x => Sentence(wordCountMin, wordCountMax))); - public static IEnumerable Paragraphs(int wordCountMin, int wordCountMax, int sentenceCount, int paragraphCount) - { - return Paragraphs(wordCountMin, wordCountMax, sentenceCount, sentenceCount, paragraphCount, paragraphCount); - } + //remove traililng space + return source.Remove(source.Length - 1); + } - public static IEnumerable Paragraphs(int wordCountMin, int wordCountMax, int sentenceCountMin, int sentenceCountMax, int paragraphCount) - { - return Paragraphs(wordCountMin, wordCountMax, sentenceCountMin, sentenceCountMax, paragraphCount, paragraphCount); - } + public static IEnumerable Paragraphs(int wordCount, int sentenceCount, int paragraphCount) + { + return Paragraphs(wordCount, wordCount, sentenceCount, sentenceCount, paragraphCount, paragraphCount); + } - public static IEnumerable Paragraphs(int wordCountMin, int wordCountMax, int sentenceCountMin, int sentenceCountMax, int paragraphCountMin, int paragraphCountMax) - { - return Enumerable.Range(0, RandomHelper.Instance.Next(paragraphCountMin, paragraphCountMax)).Select(p => Paragraph(wordCountMin, wordCountMax, sentenceCountMin, sentenceCountMax)).ToArray(); - } + public static IEnumerable Paragraphs(int wordCountMin, int wordCountMax, int sentenceCount, int paragraphCount) + { + return Paragraphs(wordCountMin, wordCountMax, sentenceCount, sentenceCount, paragraphCount, paragraphCount); + } - #endregion + public static IEnumerable Paragraphs(int wordCountMin, int wordCountMax, int sentenceCountMin, int sentenceCountMax, int paragraphCount) + { + return Paragraphs(wordCountMin, wordCountMax, sentenceCountMin, sentenceCountMax, paragraphCount, paragraphCount); + } - #region Color + public static IEnumerable Paragraphs(int wordCountMin, int wordCountMax, int sentenceCountMin, int sentenceCountMax, int paragraphCountMin, int paragraphCountMax) + { + return Enumerable.Range(0, RandomHelper.Instance.Next(paragraphCountMin, paragraphCountMax)).Select(p => Paragraph(wordCountMin, wordCountMax, sentenceCountMin, sentenceCountMax)).ToArray(); + } - /* http://stackoverflow.com/a/1054087/234132 */ - public static string HexNumber(int digits) - { - byte[] buffer = new byte[digits / 2]; - RandomHelper.Instance.NextBytes(buffer); - string result = String.Concat(buffer.Select(x => x.ToString("X2")).ToArray()); + #endregion - if (digits % 2 == 0) - { - return result; - } + #region Color - return result + RandomHelper.Instance.Next(16).ToString("X"); - } + /* http://stackoverflow.com/a/1054087/234132 */ + public static string HexNumber(int digits) + { + byte[] buffer = new byte[digits / 2]; + RandomHelper.Instance.NextBytes(buffer); + string result = String.Concat(buffer.Select(x => x.ToString("X2")).ToArray()); - #endregion - } + if (digits % 2 == 0) + { + return result; + } + + return result + RandomHelper.Instance.Next(16).ToString("X"); + } + + #endregion + } } \ No newline at end of file diff --git a/Lorem.NET/bin/Release/LoremNET.dll b/Lorem.NET/bin/Release/LoremNET.dll index 5a0bbef..9a00373 100644 Binary files a/Lorem.NET/bin/Release/LoremNET.dll and b/Lorem.NET/bin/Release/LoremNET.dll differ diff --git a/Lorem.NET/bin/Release/LoremNET.pdb b/Lorem.NET/bin/Release/LoremNET.pdb index 39a9d93..86d39df 100644 Binary files a/Lorem.NET/bin/Release/LoremNET.pdb and b/Lorem.NET/bin/Release/LoremNET.pdb differ diff --git a/Lorem.NET/obj/Release/DesignTimeResolveAssemblyReferencesInput.cache b/Lorem.NET/obj/Release/DesignTimeResolveAssemblyReferencesInput.cache index ee41c15..2a12e84 100644 Binary files a/Lorem.NET/obj/Release/DesignTimeResolveAssemblyReferencesInput.cache and b/Lorem.NET/obj/Release/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/Lorem.NET/obj/Release/Lorem.NET.csproj.FileListAbsolute.txt b/Lorem.NET/obj/Release/Lorem.NET.csproj.FileListAbsolute.txt index 903db40..6eecebb 100644 --- a/Lorem.NET/obj/Release/Lorem.NET.csproj.FileListAbsolute.txt +++ b/Lorem.NET/obj/Release/Lorem.NET.csproj.FileListAbsolute.txt @@ -2,3 +2,8 @@ C:\AJ\Personal\GitHub\Lorem.NET\Lorem.NET\bin\Release\LoremNET.dll C:\AJ\Personal\GitHub\Lorem.NET\Lorem.NET\bin\Release\LoremNET.pdb C:\AJ\Personal\GitHub\Lorem.NET\Lorem.NET\obj\Release\LoremNET.dll C:\AJ\Personal\GitHub\Lorem.NET\Lorem.NET\obj\Release\LoremNET.pdb +D:\Repositories\Lorem.NET\Lorem.NET\obj\Release\Lorem.NET.csprojResolveAssemblyReference.cache +D:\Repositories\Lorem.NET\Lorem.NET\obj\Release\LoremNET.dll +D:\Repositories\Lorem.NET\Lorem.NET\obj\Release\LoremNET.pdb +D:\Repositories\Lorem.NET\Lorem.NET\bin\Release\LoremNET.dll +D:\Repositories\Lorem.NET\Lorem.NET\bin\Release\LoremNET.pdb diff --git a/Lorem.NET/obj/Release/LoremNET.dll b/Lorem.NET/obj/Release/LoremNET.dll index 5a0bbef..9a00373 100644 Binary files a/Lorem.NET/obj/Release/LoremNET.dll and b/Lorem.NET/obj/Release/LoremNET.dll differ diff --git a/Lorem.NET/obj/Release/LoremNET.pdb b/Lorem.NET/obj/Release/LoremNET.pdb index 39a9d93..86d39df 100644 Binary files a/Lorem.NET/obj/Release/LoremNET.pdb and b/Lorem.NET/obj/Release/LoremNET.pdb differ