Make Random String - CSharp System

CSharp examples for System:Random

Description

Make Random String

Demo Code


using System.Text;
using System;/*from w w  w .  j  a  va2 s.  c om*/

public class Main{
        public static string MakeRandomString(string pwdchars, int pwdlen)
        {
            StringBuilder builder = new StringBuilder();
            Random random = new Random();
            for (int i = 0; i < pwdlen; i++)
            {
                int num = random.Next(pwdchars.Length);
                builder.Append(pwdchars[num]);
            }
            return builder.ToString();
        }
}

Related Tutorials