Random Number as string value - CSharp System

CSharp examples for System:Random

Description

Random Number as string value

Demo Code


using System.Text;
using System.Diagnostics;
using System.Collections.Generic;
using System;//w w  w.  ja v a2s. c  om

public class Main{

        public static string RndNum(int codeNum)
        {
            StringBuilder sb = new StringBuilder(codeNum);
            Random rand = new Random();
            for (int i = 1; i < codeNum + 1; i++)
            {
                int t = rand.Next(9);
                sb.AppendFormat("{0}", t);
            }
            return sb.ToString();

        }
}

Related Tutorials