Wednesday, February 1, 2012

AutoGenerate Id in asp.net

 
  int value = 12345;
        string alphabet = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ";
        var stack = new Stack<char>();
        while (value > 0)
        {
            stack.Push(alphabet[value % alphabet.Length]);
            value /= alphabet.Length;
        }
        string output = new string(stack.ToArray()).PadLeft(6, '0');
  private string GenerateId()
    {
        long i = 1, j = -1;
        foreach (byte b in Guid.NewGuid().ToByteArray()) { i *= ((int)b + 1); }
        foreach (byte b in Guid.NewGuid().ToByteArray()) { j *= ((int)b + 1); }
        var str1 = string.Format("{0:x}", (i - DateTime.Now.Millisecond));
        var str2 = string.Format("{0:x}", (j - DateTime.Now.Millisecond));
        return "EMC" + str1.Substring(0, 4) + str2.Substring(str2.Length / 2, 3);
    }






No comments:

Post a Comment

Comments

Search

Custom Search
Protected by Copyscape Plagiarism Software