getting a unique number

# Thread: getting a unique number

1. Senior Member
Join Date
Dec 1969
Posts
626

## getting a unique number

i have a long loop with many variables.<BR><BR>These variables cannot be the same... such as:<BR>numbera = 1<BR>numberb = 7<BR>numberc = 1<BR><BR>I am using a random function to get each number.<BR><BR>Is there a way I can say:<BR>numbera = [some random number]<BR>numberb = [some random number]<BR><BR>if numberb = numbera then<BR>numberb = [some random number]<BR>end if<BR><BR>and loop it so if numberb equals numbera it will re-randomize it until it is not equal to numbera...<BR><BR>I have a long list of numbers that have to be random, yet unique.

2. Senior Member
Join Date
Dec 1969
Posts
184

## RE: getting a unique number

How many variables? Is it a set number? If so just use an array...actually, use an array either way, and if you end up using more than have you alotted for, use "redim preserve"....

3. Senior Member
Join Date
Dec 1969
Posts
96,118

## ASPFAQs, category Math

http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=114<BR><BR>Does that do what you want?<BR><BR>If the numbers have to be random in a range that is much larger than the number of variables, then this isn&#039;t a good way. But if you need, for example, 20 different random numbers from (say) 1 to 100, this would work just fine.<BR><BR>If 20 different numbers from 1 to 1000, I&#039;d do it another way.<BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
626

## RE: ASPFAQs, category Math

Yea, I&#039;m just taking replacing numbers with letters in the alphabet. But I want it random each time i do it. So 26 letters, 10 random numbers from 1 - 26...

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## Oh! Much better way to do that!

&nbsp;<BR>&#060;%<BR>letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"<BR><BR>RANDOMIZE<BR>< BR>Function GetRandomLetter( )<BR> Dim LNum, RLetter<BR> &#039; catch errors:<BR> If Len(letters) = 0 Then <BR> GetRandomLetter = "?" &#039; or whatever you wish<BR> Exit Function &#039; quit with error indicator<BR> End If<BR><BR> &#039; get a number from 1 to length of remaining letters<BR> LNum = INT( RND() * Len(letters) ) + 1 <BR> &#039; get the letter corresponding to that number<BR> RLetter = Mid( letters, LNum, 1 ) <BR> &#039; *remove* that letter from the list of available letters!<BR> letters = Replace( letters, RLetter, "" )<BR> &#039; and return the selected letter<BR> GetRandomLetter = RLetter<BR>End Function<BR>%&#062;<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•