Added: April/27/2004 at 8:12pm | IP Logged
|
|
|
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.
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.
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 %> "BANNER_ADS/ITSHUGE.gif" <% Case 2 %> "BANNER_ADS/STACKED_DEEP.gif" <% Case 3 %> "BANNER_ADS/ITSHUGE.gif" <% Case 4 %> "BANNER_ADS/STACKED_DEEP.gif" <% Case 5 %> "BANNER_ADS/ITSHUGE.gif" <% Case 6 %> "BANNER_ADS/STACKED_DEEP.gif" <% Case 7 %> "BANNER_ADS/ITSHUGE.gif" <% Case 8 %> "BANNER_ADS/STACKED_DEEP.gif" <% Case 9 %> "BANNER_ADS/ITSHUGE.gif" <% Case 10 %> "BANNER_ADS/STACKED_DEEP.gif" <% End Select %>
__________________
Chris Williams
http://www.PowerASP.com
|