Unique id to be generated in Alphanumeric Formation. in asp.net
Loading
Unique id to be generated in Alphanumeric Formation. in asp.net
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh KumarRank #91 · 22.9K reputationPosted May 11, 2023, 4:41 AM EDT
Hello,
you can use Guid to generate uniq id,
string uniqueId = Guid.NewGuid().ToString();OR
string uniqueID = string.Format("{0}{1}", Guid.NewGuid().ToString("N").Substring(0, 5), DateTime.Now.ToString("yyyyMMddHHmmssfff")); // uniqueID will be a 19 character alphanumeric string, like: // "3cd3a202108091313432"Jagapathibabu Banoth166 reputationPosted May 11, 2023, 5:56 AM EDT
Sir I Want Genrerate Alphanumeric Like as (Re786hKhsoj@hl*kjguL) In this Formation.
Jignesh KumarRank #91 · 22.9K reputationPosted May 11, 2023, 6:28 AM EDT
public static string GenerateUniqueId() { DateTime now = DateTime.UtcNow; Random random = new Random(); int randomNumber = random.Next(100000, 999999); string uniqueIdString = string.Format("{0:yyyyMMddHHmmss}{1}", now, randomNumber); SHA256 sha256 = SHA256.Create(); byte[] hashBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(uniqueIdString)); string hashString = BitConverter.ToString(hashBytes).Replace("-", "").ToLower(); return hashString.Substring(0, 20); }Call method as below
var uniqueId = GenerateUniqueId();Vishal YelveRank #178 · 13.6K reputationPosted May 11, 2023, 7:08 AM EDT
try this
using System; public class Program { public static void Main() { string alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; string small_alphabets = "abcdefghijklmnopqrstuvwxyz"; string numbers = "1234567890"; string characters = string.Empty; characters += alphabets + small_alphabets + numbers; string otp = string.Empty; for (int i = 0; i < 15; i++) { string character = string.Empty; do { int index = new Random().Next(0, characters.Length); character = characters.ToCharArray()[index].ToString(); } while (otp.IndexOf(character) != -1); otp += character; } Console.WriteLine(otp); } }