How to Generates 10 Alphanumeric Random Codes in C#?

Rajnilari2015
Posted by Rajnilari2015 under C# category on | Points: 40 | Views : 281
The below program will help to do so


using System;
using System.Linq;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var str = GenerateTenRandomAlphanumericCode();
}

public static string GenerateTenRandomAlphanumericCode()
{
string code = string.Empty;

var chars = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890";
var random = new Random();
var result = new string(
Enumerable.Repeat(chars, 10)
.Select(s => s[random.Next(s.Length)])
.ToArray());
code = result;
return code;
}
}
}

Comments or Responses

Login to post response