|
-
Jun 15th, 2010, 07:23 PM
#1
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.
-
Jun 15th, 2010, 07:44 PM
#2
Thread Starter
Addicted Member
Re: No recurrence random words [Ok]
OK, so what way do you advise me to check if the word already left?
Thanks!
-
Jun 16th, 2010, 01:58 AM
#3
Re: No recurrence random words [Ok]
 Originally Posted by Ellis Dee
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.
-
Jun 16th, 2010, 02:24 AM
#4
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|