Generating Random Number Using RND Function And Randomize Statement
We will use RDN function to generate a random number. Our first example generates a random number between 1 ~ 10.
Example 1
<%@ Page Language="VB" Debug="true" %>
<script runat="server">
Sub Page_Load(Source as Object, E as EventArgs)
Dim i as integer
i = CInt(Int((10 * Rnd()) + 1))
example.InnerHtml = "Random Number : " & i
end sub
</script>
<SPAN id=example runat="server" />
i = CInt(Int((10 * Rnd()) + 1))
In this example we put a limited number for our result. Here, 10 is the upperbound for our random number, Our lowerbound is 1. Becuase we do not want to generate a random number equals to 0 (zero). Our script will generate a random number from 1 to 10.
Now we will generate a random number using randomize statement. You will add only a line same code. Add 'randomize' code inside of your original code. Randomize generates a number from system timer, then RDN function uses this number to generate a random number. Therefore if you use 'randomize', mostly you will get more different numbers.
Example 2
<%@ Page Language="VB" Debug="true" %>
<script runat="server">
Sub Page_Load(Source as Object, E as EventArgs)
Dim i as integer
Randomize
i = CInt(Int((10 * Rnd()) + 1))
example.InnerHtml = "Random Number : " & i
end sub
</script>
<SPAN id=example runat="server" />
- ASP Chat Box
- Working with Array Remove An Item
- ASPNET Web Counter Free Open Source Code
- Beginning-Ajax-and-ASPNET-35
- How to upload images to mySQL within PHP
- Delete Files Online in ASP
- Video Interview With Roman Strobl
- Custom Paging in ASP Fast And Easy
- How to write and use a JavaBean My frst java bean
- Displaying Records From An Excel Database
- Converting sceonds to hours minutes and seconds
- Paging Results in PHP
- Installing Sun Java System Application Server 9.1 in Solaris Zones
- Java SE 6 Performance White Paper
- Encoding URL strings
- Easy Download Manager Free Version
- ASP Chat Box
- Writing Form Data to Text Files
- Paging Records in JSP
- What is Ecommerce and the Importance of Ecommerce
- Beginning-Ajax-and-ASPNET-35
- How to upload images to mySQL within PHP
- Simple XML RSS Parser
- Counting records in PHP mySQL
- ActiveNews Manager Freeware News Exchange Software
- How to write and use a JavaBean My frst java bean
- Paging Results in PHP
- Free User Registration Form
- A-timesaver-control-GridView
- ASPNET Web Counter Free Open Source Code
- Easy Download Manager Free Version
- ASP Chat Box
- Writing Form Data to Text Files
- Paging Records in JSP
- Beginning-Ajax-and-ASPNET-35
- How to upload images to mySQL within PHP
- Simple XML RSS Parser
- ActiveNews Manager Freeware News Exchange Software
- Counting records in PHP mySQL
- How to write and use a JavaBean My frst java bean
- Paging Results in PHP
- Free User Registration Form
- A-timesaver-control-GridView
- ASPNET Web Counter Free Open Source Code
- Comparing Dates