Get Random String - CSharp System

CSharp examples for System:Random

Description

Get Random String

Demo Code


using System.Security.Cryptography;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*from  ww w .  j  a  v  a2s  .c om*/

public class Main{
        /// <summary>
        /// Get Random 
        /// </summary>
        /// <param name="Length"></param>
        /// <returns></returns>
        private static string GenerateRandom(int Length)
        {
            System.Text.StringBuilder newRandom = new System.Text.StringBuilder(62);
            Random rd = new Random();
            for (int i = 0; i < Length; i++)
            {
                newRandom.Append(constant[rd.Next(62)]);
            }
            return newRandom.ToString();
        }
}

Related Tutorials