Generate Random Numbers in Asp.Net C#

Generate Random Numbers

Generate Random Numbers  in Add the Minimum & Maximum Range Control to Refresh  Ajax Timer & Script Manager in Asp.Net C#.

                            Download Coding



random.Next(int Minimum ,int Maximum)

Html Coding

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <br />
        <asp:Label ID="lblRandom1" runat="server" ForeColor="#CC3300"></asp:Label>
        <br />
        <asp:Label ID="lblRandom2" runat="server" ForeColor="#CC66FF"></asp:Label>
        <br />
        <asp:Label ID="lblRandom3" runat="server" ForeColor="#CC3300"></asp:Label>
        <br />
        <asp:Label ID="lblRandom4" runat="server" ForeColor="#CC66FF"></asp:Label>
        <br />
        <asp:Label ID="lblRandom5" runat="server" ForeColor="#CC3300"></asp:Label>
        <br />
        <br />
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        <br />
        <asp:Timer ID="Timer1" runat="server" Interval="3000">
        <br />

C# Coding

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Randoms : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        //  rm.Next(Minimum Number,Maximun Number)

        Random rm = new Random();

        lblRandom1.Text = "1st Number="  +   rm.Next(1, 10).ToString();
        lblRandom2.Text = "2nd Number=" + rm.Next(1, 10).ToString();
        lblRandom3.Text = "3rd Number=" + rm.Next(1, 10).ToString();
        lblRandom4.Text = "4th Number=" + rm.Next(1, 10).ToString();
        lblRandom5.Text = "5th Number=" + rm.Next(1, 10).ToString();


First Create the New WebForm - Add the Labels & Ajax Timer & Script Manager

Next - AJAX Timer Set the Interval Time =3000 (3 Seconds)

Next - Code Behind  Page_Load  - Add the Random Minimum & Maximum Range.


Next - Run[F5] The Program - Get the Random Numbers


Post a Comment