Generating Random Number in ASP
Generating random numbers is very important in programming. We have to use random numbers to show a random record (Image, Saying, Article etc.) on our pages. Also, we can use random numbers for everything that we can imagine. In this article, we will see easiness of generating random numbers with ASP.
Structure 1.0:
Formula: 0 <= result < MaxNumber
At line 2, randomize statement is used to generate a different number for each time we call the rnd() function.
At line 3, a random number was generated between 0 and MaxNumber variable but except the MaxNumber’s value, was converted integer with int() function and was printed. Let’s make an example.
Example 1.0: This usage gives us a random number between 0 and 100 but except 100. Minimum value of generated number can be 0 and maximum value of generated number can be 99, can not be 100.
Probable Output of Example 1.0:
1.1) Generating a Random Number Between Two Numbers
Structure 1.1: If we want to generate a random number between two numbers (that we determined), we should define a StartValue variable. We can make it like this:
Formula: StartValue <= result < MaxNumber
Example 1.1: With this usage, a random number is generated between 1000 and 2000 but except 2000.
1.2) Getting a Random Element from a Collection
Example 1.2: Assume that we need to get a random item from an array.
Let’s improve our example…
Example 1.3: This time, we going to get multiple items from an array.
Probable Output of Example 1.3:
A Little Homework For You
As you see, it is possible getting duplicate elements. So, try to make an application that gets every single element from array only once.

Recently Typed