|
-
Oct 3rd, 2004, 06:15 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Randoming Unique Numbers
Hi guyz... One quick help, ummm I want to have a set of random numbers from 0 - 69. For example I have an array Set(70) and Set(0) will be 45, Set(1) will be 32, Set(2) will be 10, Set(3) will be 65, and so on.. What I need is to fill the entire Set() with numbers from 1 to 70 all randomly positioned, and no repeating numbers. Got it?
I tried this one with my code, It worked pretty well for 0 - 19, but when I was trying 0 - 69 im getting an endless loop with my code
VB Code:
Public Sub Randomize()
Dim aCtr As Long, bCtr As Long, nowIndex As Long, pastIndex (TOTAL) As Long, duplicate As Boolean
duplicate = True
For aCtr = 0 To (TOTAL - 1)
pastIndex(aCtr) = -1
Next
For aCtr = 0 To TOTAL_CARDS - 1
Do While duplicate = True
nowIndex = Round(Rnd() * 20)
For bCtr = 0 To TOTAL - 1
If pastIndex(bCtr) <> nowIndex Then
duplicate = False
Else
duplicate = True
Exit For
End If
Next
Loop
For bCtr = 0 To TOTAL - 1
If pastIndex(bCtr) = -1 Then
pastIndex(bCtr) = nowIndex
Exit For
End If
Next
duplicate = True
Next
End Sub
what could be wrong with my code? Have I over looped? or its just not the way its suppose to be. I havent done this randomizing exercise before..
Need Help... Thanks for all the help....Love yah guyz
Last edited by charmedcharmer; Oct 4th, 2004 at 05:38 AM.
C++ Programming is overwhelming.
Dont let it overwhelm you or you'll fall into the oblivion of its perfection
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|