Monday, 21 March 2016

How to Generate Random Number(only Numbers) in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
protected void Page_Load(object sender, EventArgs e)
    {
        int ranid = RandomNumber(00000, 9999999);
        number.Text = ranid.ToString();       
    }
    private int RandomNumber(int min, int max)
    {
        Random random = new Random();
        return random.Next(min, max);
    }
o/p:number.Text: 8598736

No comments: