ASP Random number generator

We can generate random number for our applications using ASP. The random number can be used for displaying random images, or random banners or random colors for a page or random numbers for any type of application. To generate random number we have to initiate random number generator first by using randomize function. Here is the code to generate random number between 1 and 10

Dim my_num
Randomize
my_num = Int((rnd*10))+1
Response.Write my_num

The function rnd returns random number between 0 and .9 so we have multiplied it by 10 to move the decimal place one step right. Then took the integer part by using Int function, then we have added 1 to it.

We can also give a range of number and generate random number between the given maximum and minimum numbers. Here is the code.

Dim my_num,max,min

max=5
min=2

Randomize
my_num=int((max-min+1)*rnd+min)
Response.Write my_num

Be the first to post comment on this article :





Further readings
Round function to format decimal place in a number
Math functions INT
Random Number generator using Random function
Percentage value by using FormatPerecnt function

Post your comments , suggestion , error , requirements etc here .




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer