var rand = new Random(); string str = "0"; const string chars = "ABCDEF0123456789"; str += new string(Enumerable.Repeat(chars, 31) .Select(s => s[rand.Next(s.Length)]).ToArray()); return str;