Created
September 26, 2014 03:33
-
-
Save hoangitk/ec89b359dca685ed129c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| static string uniqueCode() | |
| { | |
| string characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#"; | |
| string ticks = DateTime.UtcNow.Ticks.ToString(); | |
| var code = ""; | |
| for (var i = 0; i < characters.Length; i += 2) | |
| { | |
| if ((i + 2) <= ticks.Length) | |
| { | |
| var number = int.Parse(ticks.Substring(i, 2)); | |
| if (number > characters.Length - 1) | |
| { | |
| var one = double.Parse(number.ToString().Substring(0, 1)); | |
| var two = double.Parse(number.ToString().Substring(1, 1)); | |
| code += characters[Convert.ToInt32(one)]; | |
| code += characters[Convert.ToInt32(two)]; | |
| } | |
| else | |
| code += characters[number]; | |
| } | |
| } | |
| return code; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment