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
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


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 Comment This is for short comments only. Use the forum for more discussions.

Subscribe to our mailing list

* indicates required
Subscribe to plus2net
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2018 All rights reserved worldwide Privacy Policy Disclaimer