|
-
Jul 14th, 2000, 05:07 AM
#1
Thread Starter
Addicted Member
what is the fastest way to randomize a list, in your opinion? i have a few ideas but i just wanna know if someone has any really fast way of doing it
-
Jul 14th, 2000, 06:29 AM
#2
Lively Member
?
What do you mean by "randomize a list"? Are you saying you have a bunch of items in a list that you want re-ordered or an array that you want reordered or that you just want to select items randomly?
Toot
Some cause happiness wherever they go; others, whenever they go.
-
Jul 14th, 2000, 07:45 AM
#3
Addicted Member
I suppose this depends on the size of the list. As with sort methods there are various ways of doing it, but the overhead (or efficiency) is directly related to the size of the collectiong being sorted.
What are you trying to do, specifically and what size is the list?
-
Jul 14th, 2000, 08:58 AM
#4
Fanatic Member
how about this ???
Code:
Public Sub Unsort(List() As Long, min As Long, max As Long)
Dim i As Long
Dim pos As Long
Dim tmp As Long
For i = min To max - 1
pos = Int((max - i + 1) * Rnd + i)
tmp = List(pos)
List(pos) = List(i)
List(i) = tmp
Next i
End Sub
Paul Dwyer 
Network Engineer
Aussie In Tokyo
Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)
-
Jul 14th, 2000, 09:04 AM
#5
Addicted Member
Its not inconceivable that the same random number occurs more than once. I would remove the item and place a NULL there. Then check for NULL prior to extracting ListItem. May then have to loop more than ListSize, but could increment counter as required.
Otherwise an excellent response Paul282.
-
Jul 14th, 2000, 09:08 AM
#6
Thread Starter
Addicted Member
Originally posted by Steven McGarva
Its not inconceivable that the same random number occurs more than once. I would remove the item and place a NULL there. Then check for NULL prior to extracting ListItem. May then have to loop more than ListSize, but could increment counter as required.
Otherwise an excellent response Paul282.
know what would kill you? having 30 nulls and one left sitting there...
and the list could be anywhere from 5 to 5000 items, so maybe having multiple ways of randomizing it would be good
-
Jul 14th, 2000, 09:21 AM
#7
Thread Starter
Addicted Member
ok, i just tried my idea... it's the only one i can come up with that makes sense:
having one unseen list, put whatever you want to randomize in the second list then going like this:
----
Do
x = Int(Rnd * List2.ListCount)
List1.AddItem (List2.List(x))
List2.RemoveItem (x)
Loop Until List2.ListCount = 0
----
-
Jul 14th, 2000, 09:37 AM
#8
Fanatic Member
Having multiple numbers pop up in the random number seed is not a big deal as it's swaping values sequentially (ie some numbers being swapped have already been moved once), it's also possible that after one swap a random number will reset a value to it's initial position... so what? it's random. If there is no chance of this happening then you're really just ordering to an obscure pattern.
You didn't specify your objective just to 'randomize'. 'randomize' implies that some digits may stay in the same place
I don't understand about the NULL arguement ????? you're always swapping a value not just moving it, try the function on a big list of numbers and see if any nulls or gaps appear.
works sort of like a backward selection-sort
Paul Dwyer 
Network Engineer
Aussie In Tokyo
Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)
-
Jul 14th, 2000, 10:16 AM
#9
Thread Starter
Addicted Member
i just don't see how the topic "randomize a list" could be taken as anything but randomizing the possitions of list items... i.e. misc - sort - Randomize list in winamp.. at any rate, i figured out how to do it with just one list:
Code:
For x = 0 To List1.ListCount - 1
y = Int(Rnd * (List1.ListCount - (x + 1))) + x - 1
temp$ = List1.List(x)
temp2$ = List1.List(y)
List1.RemoveItem (x)
List1.AddItem temp2$, x
List1.RemoveItem (y)
List1.AddItem temp$, y
Next
and i think that's what winamp does, because sometimes you can see the items in the playlist being replaced
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
|