- ASP - Random Functions
·Script Writers
·Database Display
·Response Objects
·Server Variables
·Random Events
·What's New?
Mail List


Unique Random Numbers
There are many things you can do to randomize content in your .asp document, however if you use one element repeatedly you run the risk of generating the same random value/content within a page. To avoid that you can make sure you random items (in this case numbers) are unique. The following example will generate five random numbers between one through five. After each random number is selected it is compared to the previous selections and if it was previously selected a new number is chosen. This is great for randomizing the order of content on a page.
View the Output
Text View
Print View
Mail this Link
Download the Code

<title> Random Numbers)</title>
<body bgcolor="#FFFFFF">
' Determines how many unique random numbers to be produced

' Determines the highest value for any unique random number
dim random_number, counter, check, unique_numbers
' When passing a varible for an array use redim
redim random_number(tot_unique)
' begin random function
' Begin a for next loop from one to the max number of unique numbers
For counter = 1 to tot_unique
' select a number between 1 and the top number value
random_number(counter) = Int(Rnd * top_number)+1
' For next loop to compare the values stored in the array to
' the new random value being assigned
for check=1 to counter-1
if random_number(check)= random_number(counter) then
' If the current value is equal to a previous value
' subject
end if
next ' Repeat loop to check values
next ' Repeat loop to assign values to the array

<ol><% 'write out the unique numbers in a list for display
For counter = 1 to tot_unique
response.write "<li>" & random_number(counter) & "</li>"







ASP: What's New? | Articles | Script Writers | Database Display | Read/Write
Server Variables | Response Objects | Random Events | Miscellaneous
HTML: Forms | Hyperlinks | Headers | Tables | Hyperlinks | Headers | Text Display
JavaScript: Document Info | Forms | Images | Navigation | Script Writers
CSS: Basics | Page Display | Text Display | Script Writers | Miscellaneous
  • 2014 michael kors
  • air max women 2013
  • 2014 michael kors
  • air max 2014
  • oakley glasses
  • oakley glasses

  • Maps: Map Script Writers | Bing Maps | Google Maps
  • bottes fr
  • ugg boot
  • Privacy Statement is hosted by
    Donate Food Online with a Mouse Click at
    Donate Land Online with a Mouse Click at
    © 1999 - 2018
    All Rights Reserved

  • Kids jordan 6 rings
  • Jordan retro 10
  • Jordan retro 3