Results 1 to 5 of 5

Thread: [RESOLVED] Randoming Unique Numbers

Threaded View

  1. #1

    Thread Starter
    Addicted Member charmedcharmer's Avatar
    Join Date
    Sep 2003
    Posts
    211

    Resolved [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:
    1. Public Sub Randomize()
    2.    Dim aCtr As Long, bCtr As Long, nowIndex As Long, pastIndex  (TOTAL) As Long, duplicate As Boolean
    3.    
    4.    
    5.    
    6.    duplicate = True
    7.    For aCtr = 0 To (TOTAL - 1)
    8.       pastIndex(aCtr) = -1
    9.    Next
    10.  
    11.    For aCtr = 0 To TOTAL_CARDS - 1
    12.       Do While duplicate = True
    13.          nowIndex = Round(Rnd() * 20)
    14.          
    15.          
    16.          For bCtr = 0 To TOTAL - 1
    17.             If pastIndex(bCtr) <> nowIndex Then
    18.                duplicate = False
    19.             Else
    20.                duplicate = True
    21.                Exit For
    22.             End If
    23.          Next
    24.       Loop
    25.      
    26.       For bCtr = 0 To TOTAL - 1
    27.          If pastIndex(bCtr) = -1 Then
    28.             pastIndex(bCtr) = nowIndex
    29.             Exit For
    30.          End If
    31.       Next
    32.          
    33.       duplicate = True
    34.    Next
    35.    
    36.    
    37.      
    38. 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
  •  



Click Here to Expand Forum to Full Width