Classic ASP random numbers with Rnd not working?

Ok, ok, I'll be the first to admit: I'm not the greatest in Classic ASP at this point. I've worked in it but it's been a few years since I did anything serious and that was in ASP.NET anyway. And really, if you're developing for the web, why the hell would you use a Windows server anyway? Why straggle by in old-school ASP when I can murder fools in PHP5?

Anyway, I digress. While Googling to find a way to generate a random number in ASP I found tons of posts about the Rnd function. Simple function, it returns a random number greater or equal to 0 and less than 1. So, to get a random number between 1 and 5, in classic ASP, you can do something like this:

intRange = 5

dim intRandom
' get a random integer between 1 and the number of offers
intRandom = Int(Rnd * intRange) + 1

Pretty simple, right? Oh no my friends, nothing is ever simple on IIS. This script will return a random number, for sure: ONCE. After that, the 'random' value will be cached by IIS so every time the client loads the page the get the same 'random' value. Not so random now, is it? I pulled my hair out for an hour, reading about IIS caching bugs and how to disable IIS's cache, but then I moved the page over to my testing server and got the same result.

The fix? Add this line at the very top:

Randomize

That's it. Don't ask my why, by this will make IIS re-generate your values every time the page is requested. I'm sure it has some interesting background but at this point, I don't care, I'm just glad this little nugget is done and I can go back to LAMP. Just to review, the ASP random number script now looks like:

<%

Randomize

' put the upper bound (inclusive) for your range here
intRange = 5

dim intRandom
' get a random integer between 1 and the number of offers
intRandom = Int(Rnd * intRange) + 1

%>

then, later in the page, use

<% Response.Write intRandom %>

if you want to echo the value. More than likely though, you'll use this to randomize some adverts or rotating offers or something similar. Tag a select case and some blocks of HTML onto the end of the script and you'll be rocking and rollin'.

[a]

Problem with activation

Hi there, I dont know if I am writing in a proper board but I have got a problem with activation, link i receive in email is not working... http://siliconrockstar.com/?bb3997bad7245bc733be44d24a1,

Sorry about that

Lol, sorry about that, I didnt' realize Drupal was sending out activation links. You should be able to post comments without having to activate an account. Please be patient with me, as of late I haven't had much time to go through the comments and approve them so it may take a few days for your comment to show up. Thanks for participating!

[andy]