Skip to content

Commit

Permalink
feature: adds a new generate method to generate a short id of a given…
Browse files Browse the repository at this point in the history
… length
  • Loading branch information
Bolorunduro Winner-Timothy B committed Jun 13, 2017
1 parent 1b494d2 commit 43bda18
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
4 changes: 2 additions & 2 deletions shortid.Test/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 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")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
3 changes: 0 additions & 3 deletions shortid.Test/shortid.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="nunit.framework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb">
<HintPath>..\packages\NUnit.3.5.0\lib\net45\nunit.framework.dll</HintPath>
</Reference>
Expand Down
8 changes: 4 additions & 4 deletions shortid/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("shortid")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("A random string ID generator")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("Bolorunduro Winner-Timothy")]
[assembly: AssemblyProduct("shortid")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
Expand All @@ -32,5 +32,5 @@
// 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")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
14 changes: 12 additions & 2 deletions shortid/ShortId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,24 @@ public static string Generate(bool useNumbers, bool useSpecial, int length)
{
pool += Specials;
}

string output = string.Empty;
for (int i = 0; i < length; i++)
{
int charIndex = Random.Next(0, pool.Length);
output += pool[charIndex];
}
return output;
}
}

/// <summary>
/// Generates a random string of a specified length
/// </summary>
/// <param name="length">The length of the generated string</param>
/// <returns>A random string</returns>
public static string Generate(int length)
{
return Generate(false, true, length);
}
}
}
3 changes: 0 additions & 3 deletions shortid/shortid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ShortId.cs" />
Expand Down

0 comments on commit 43bda18

Please sign in to comment.