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
This article is written by plus2net.com team.
Be the first to post comment on this article :
plus2net.com
|