Created
April 3, 2011 08:42
-
-
Save mitchdenny/900302 to your computer and use it in GitHub Desktop.
The purpose of this class is to generate a random short URL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public static class ShortUrlTokenGenerator | |
{ | |
private const string alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"; | |
private static Random generator = new Random(); | |
public static string GenerateToken(int tokenLength) | |
{ | |
var builder = new StringBuilder(); | |
for (var tokenIndex = 0; tokenIndex < tokenLength; tokenIndex++) | |
{ | |
var randomCharacterIndex = generator.Next(alphabet.Length); | |
builder.Append(alphabet[randomCharacterIndex]); | |
} | |
return builder.ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment