first commit

This commit is contained in:
dochoffiday 2014-08-19 16:23:08 -04:00
commit 4b66d928ce
16 changed files with 344 additions and 0 deletions

27
Lorem.NET.sln Normal file
View file

@ -0,0 +1,27 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lorem.NET", "Lorem.NET\Lorem.NET.csproj", "{787D3BA7-DB6C-4704-B89C-8D91A4392442}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{438E4420-54B2-45AC-B8C8-010BE97875F3}"
ProjectSection(SolutionItems) = preProject
readme.md = readme.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{787D3BA7-DB6C-4704-B89C-8D91A4392442}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{787D3BA7-DB6C-4704-B89C-8D91A4392442}.Debug|Any CPU.Build.0 = Debug|Any CPU
{787D3BA7-DB6C-4704-B89C-8D91A4392442}.Release|Any CPU.ActiveCfg = Release|Any CPU
{787D3BA7-DB6C-4704-B89C-8D91A4392442}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

BIN
Lorem.NET.v12.suo Normal file

Binary file not shown.

28
Lorem.NET/Extensions.cs Normal file
View file

@ -0,0 +1,28 @@
using System;
namespace Lorem.NET
{
internal static class Extensions
{
internal static String Remove(this string s, string pattern)
{
return s.Replace(pattern, "");
}
internal static String[] Split(this string s, string separator)
{
return s.Split(new[] { separator }, StringSplitOptions.None);
}
internal static string UppercaseFirst(this string s)
{
// Check for empty string.
if (string.IsNullOrEmpty(s))
{
return string.Empty;
}
// Return char and concat substring.
return char.ToUpper(s[0]) + s.Substring(1);
}
}
}

View file

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{787D3BA7-DB6C-4704-B89C-8D91A4392442}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Lorem.NET</RootNamespace>
<AssemblyName>Lorem.NET</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Extensions.cs" />
<Compile Include="Lorem.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RandomHelper.cs" />
<Compile Include="Source.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

130
Lorem.NET/Lorem.cs Normal file
View file

@ -0,0 +1,130 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace Lorem.NET
{
public class Lorem
{
public static bool Chance(int successes, int attempts)
{
var number = Number(1, attempts);
return number <= successes;
}
public static T Random<T>(T[] items)
{
var index = RandomHelper.Instance.Next(items.Length);
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);
return (Math.Abs(longRand % ((max + 1) - min)) + min);
}
#region DateTime
public static DateTime DateTime(int startYear = 1950, int startMonth = 1, int startDay = 1)
{
return DateTime(new System.DateTime(startYear, startMonth, startDay), System.DateTime.Now);
}
public static DateTime DateTime(DateTime min)
{
return DateTime(min, 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;
}
#endregion
#region Text
public static string Email()
{
return string.Format("{0}@{1}.com", Lorem.Words(1, false), Lorem.Words(1, false));
}
public static string Words(int wordCount, bool uppercaseFirstLetter = true, bool includePunctuation = false)
{
return Words(wordCount, wordCount, uppercaseFirstLetter, includePunctuation);
}
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)));
if (uppercaseFirstLetter)
{
source = source.UppercaseFirst();
}
return source;
}
public static string Sentence(int wordCount)
{
return Sentence(wordCount, wordCount);
}
public static string Sentence(int wordCountMin, int wordCountMax)
{
return string.Format("{0}.", Words(wordCountMin, wordCountMax, true, true)).Replace(",.", ".").Remove("..");
}
public static string Paragraph(int wordCount, int sentenceCount)
{
return Paragraph(wordCount, wordCount, sentenceCount, sentenceCount);
}
public static string Paragraph(int wordCountMin, int wordCountMax, int sentenceCount)
{
return Paragraph(wordCountMin, wordCountMax, sentenceCount, sentenceCount);
}
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)));
//remove traililng space
return source.Remove(source.Length - 1);
}
public static IEnumerable<string> Paragraphs(int wordCount, int sentenceCount, int paragraphCount)
{
return Paragraphs(wordCount, wordCount, sentenceCount, sentenceCount, paragraphCount, paragraphCount);
}
public static IEnumerable<string> Paragraphs(int wordCountMin, int wordCountMax, int sentenceCount, int paragraphCount)
{
return Paragraphs(wordCountMin, wordCountMax, sentenceCount, sentenceCount, paragraphCount, paragraphCount);
}
public static IEnumerable<string> Paragraphs(int wordCountMin, int wordCountMax, int sentenceCountMin, int sentenceCountMax, int paragraphCount)
{
return Paragraphs(wordCountMin, wordCountMax, sentenceCountMin, sentenceCountMax, paragraphCount, paragraphCount);
}
public static IEnumerable<string> 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();
}
#endregion
}
}

View file

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Lorem.NET")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Lorem.NET")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("8af259ae-efba-4e62-a4db-9830488a4085")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

29
Lorem.NET/RandomHelper.cs Normal file
View file

@ -0,0 +1,29 @@
using System;
using System.Threading;
namespace Lorem.NET
{
/*
* http://stackoverflow.com/a/1785821/234132
*/
public static class RandomHelper
{
private static int seedCounter = new Random().Next();
[ThreadStatic]
private static Random rng;
public static Random Instance
{
get
{
if (rng == null)
{
int seed = Interlocked.Increment(ref seedCounter);
rng = new Random(seed);
}
return rng;
}
}
}
}

20
Lorem.NET/Source.cs Normal file
View file

@ -0,0 +1,20 @@
using System.Collections.Generic;
using System.Linq;
namespace Lorem.NET
{
internal class Source
{
const string LoremIpsum = @"lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua, ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat, duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur, excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum,";
internal static IEnumerable<string> Rearrange(string words)
{
return words.Split(" ").OrderBy(x => RandomHelper.Instance.Next());
}
internal static IEnumerable<string> WordList(bool includePuncation)
{
return includePuncation ? Rearrange(LoremIpsum) : Rearrange(LoremIpsum.Remove(","));
}
}
}

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,5 @@
C:\AJ\Personal\GitHub\Lorem.NET\Lorem.NET\bin\Debug\Lorem.NET.dll
C:\AJ\Personal\GitHub\Lorem.NET\Lorem.NET\bin\Debug\Lorem.NET.pdb
C:\AJ\Personal\GitHub\Lorem.NET\Lorem.NET\obj\Debug\Lorem.NET.csprojResolveAssemblyReference.cache
C:\AJ\Personal\GitHub\Lorem.NET\Lorem.NET\obj\Debug\Lorem.NET.dll
C:\AJ\Personal\GitHub\Lorem.NET\Lorem.NET\obj\Debug\Lorem.NET.pdb

Binary file not shown.

Binary file not shown.

13
readme.md Normal file
View file

@ -0,0 +1,13 @@
Lorem.NET
===============
A .NET library for all things random!
Usage
---------------
### Text Helpers
```csharp
Lorem.Words(2, 5);
```