Home | Advertising Info41 USERS CURRENTLY ONLINE   
PowerASP
   Site Search Contact Us Thursday, March 13, 2025  


Basic ASP Randomizer Example




Usage: 
Randomize(Cbyte(Left(Right(Time(),5),2)))
RANDOMVALUE = Int((Highnumber - Lownumber + 1) * Rnd + Lownumber)

The extra code added to the Randomize function ensures that you get as random a value as possible. Without it certain numbers will show up more often than others as computers are not very good at generating random values.

You don't have to use case statements, but in this example I did. There are many things you can do with the resulting value. This is just an example of using this code to generate a simple random banner rotator. You also can use response.writes to eliminate a lot of the script tags but I wanted to keep this example simple for the newbie's. It is easier to understand this way.

This code will basically give you a random Integer from a range of 1 to 10 that you do whatever you want with like make a random banner rotator. Remember you can change the highnumber and lownumber to generate a random number within a greater range. See Usage at top of this page.

<%
Randomize(Cbyte(Left(Right(Time(),5),2)))
RANDOMVALUE =(Int((10 - 1 + 1) * Rnd + 1))
Select Case RANDOMVALUE
%>


<% Case 1 %>
<img src="BANNER_ADS/ITSHUGE.gif">
<% Case 2 %>
<img src="BANNER_ADS/STACKED_DEEP.gif">
<% Case 3 %>
<img src="BANNER_ADS/ITSHUGE.gif">
<% Case 4 %>
<img src="BANNER_ADS/STACKED_DEEP.gif">
<% Case 5 %>
<img src="BANNER_ADS/ITSHUGE.gif">
<% Case 6 %>
<img src="BANNER_ADS/STACKED_DEEP.gif">
<% Case 7 %>
<img src="BANNER_ADS/ITSHUGE.gif">
<% Case 8 %>
<img src="BANNER_ADS/STACKED_DEEP.gif">
<% Case 9 %>
<img src="BANNER_ADS/ITSHUGE.gif">
<% Case 10 %>
<img src="BANNER_ADS/STACKED_DEEP.gif">
<% End Select %>

 

   Active Server Pages Rule The World
Contact Us  
All artwork, design & content contained in this site are Copyright © 1998 - 2025 PowerASP.com and Christopher J. Williams
Banner ads ,other site logos, etc are copyright of their respective companies.
STATS Unless otherwise noted - All Rights Reserved.

PowerASP active server pages asp.net microsoft .net framework sdk learn asp what is asp tutorial learn asp.net CJWSoft ASPProtect ASPBanner ASPClassifieds www.aspclassifieds.com, www.powerasp.com,www.cjwsoft.com,www.aspphotogallery.com,www.codewanker.com,www.aspprotect.com,www.aspbanner.com