fangsnclaws / Main / ASP Examples

fangsnclaws.com


"We'll sink our fangs and claws into your project!"

One Example of Random Number Usage:

Generating random numbers in ASP/VBS, (or just about any other computer language), is pretty easy since it's usually a built-in function of the language you are working with. Here is some simple ASP/VBS code to generate a random number between 1 and 10:

  Dim randy, lowerbound, upperbound, intRange, sngRandomVal
     lowerbound = 1
     upperbound = 10

Randomize()

 intRange = int(upperbound) - int(lowerbound) + 1
 sngRandomVal = int(intRange) * Rnd()
 sngRandomVal = sngRandomVal + lowerbound

     randy = int(sngRandomVal)

Okay, that's swell. But why would we ever need such a thing?

On this site I'm using random numbers to present visitors with one of several different color schemes for my site. Go back to the main page and issue a 'hard refresh' in your browser of choice, [Ctrl-F5 in Internet Explorer]. Try that a few times until the color scheme changes. That color scheme will persist throughout the remaining pages on the site ... or it will once I update the rest of my pages!


An "Inspirational" Example

Here's another example. While this example was written in PHP rather than ASP it still illustrates an application using random numbers. In this case a random number is used against a database sitting on the server to select a photograph, a 'pithy' saying, and a color scheme. This example is set up so that using a 'soft refresh' , [press your browser's refresh button], will bring up another random photo.

Inspirational Thought