Results 1 to 19 of 19

Thread: No recurrence random words [resolved]

Hybrid View

  1. #1
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: No recurrence random words [Ok]

    Note that a collection is super slow, since the way it prevents duplicates is the absolute slowest way possible. (It compares the new key to every key in the collection, every time.)

    30k items is pretty small, though, so it'll be peppy regardless of how you do it.

  2. #2

    Thread Starter
    Addicted Member *PsyKE1*'s Avatar
    Join Date
    Jun 2010
    Location
    Spain
    Posts
    243

    Re: No recurrence random words [Ok]

    OK, so what way do you advise me to check if the word already left?

    Thanks!

  3. #3
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: No recurrence random words [Ok]

    Quote Originally Posted by Ellis Dee View Post
    Note that a collection is super slow, since the way it prevents duplicates is the absolute slowest way possible. (It compares the new key to every key in the collection, every time.)
    Not true. When you add an item the Colection hashes the key, probes the hash table for a match or matches, then it compares the key against each key that hashed to the same value.

    Not peppy but nowhere near as bad as comparing the new key to every existing key.

  4. #4

    Thread Starter
    Addicted Member *PsyKE1*'s Avatar
    Join Date
    Jun 2010
    Location
    Spain
    Posts
    243

    Re: No recurrence random words [Ok]

    Code:
    Private Sub Aleatory_Comb(ByRef CharList() As String, ByVal iDigits As Integer, ByVal iNumber As Long)
        Dim sUsed As String
    	Dim sWord As String
        Dim x     As Long
        Dim y     As Long
        For y = 1 To iNumber
            For x = 1 To iDigits
                Randomize
                sWord = sWord & CharList(Rnd * (UBound(CharList()) - 1) + 1)
            Next x
    		If InStrB(1, sUsed, sWord & "|") = 0 Then
    			MsgBox sWord
    		End If
    		sUsed = sUsed & sWord & "|"
    		sWord = vbNullString
        Next y
    End Sub
    @Zach_VB6:
    Thanks but Im afraid this code dosen´t works becouse if i put in the call this:
    Code:
        Dim Matriz() As String
        Matriz = Split("a,b,c", ",")
        Call Aleatory_Comb(Matriz, 3, 1000)
    it should return me 1000 words, but I only returned 8 ... What is the problem?
    Regarding the solutions have been giving me, for now convinces me most is to keep everything in a list, and then delete duplicates, so I never have to check every time, and I think it would save much time ... but I would not know removed the repeated elements in the collection ... what is your opinion on this?

    Thank you very much
    Last edited by *PsyKE1*; Jun 16th, 2010 at 04:40 AM.

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