SQL PHP HTML ASP JavaScript articles and free scripts to download

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 :


Google+

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 Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked



HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer