how do I create a random list whilst keeping some entries fromrandomizing?

W

warren dwyer

I need to create a large number of randomly sorted lists from a single master list (random team order per event based on a list of teams entered for all events). Some of the entries must remain in the same order in each list, but the remaining entries must be shuffled.

ie. Teams are A, B, C, D, E, F, G, H, J, K and L . CD and HJK must always appear in the same order. Therefore B.CD.ME.HJK.FAGL, AF.HJK.GMLEB.CD, HJK.FL.CD.EBAGM etc are all valid solutions.

I can create a fully random list easily, but can't find an easy way to keep the important entries in the same order.

Cheers
Waz.


Submitted via EggHeadCafe - Software Developer Portal of Choice
Look Ma, No DataBase! Bamboo Prevalence
http://www.eggheadcafe.com/tutorial...d77-d3a00233c10a/look-ma-no-database-bam.aspx
 
M

michdenis

Hi,

Try this :

'--------------------------------------
Sub test()
Dim Dic As Object, Arr()
Arr = Array("A", "B", "C", "D", "E", _
"F", "G", "H", "J", "K", "L")

Set Dic = CreateObject("Scripting.Dictionary")
Do
Randomize
v = Arr(Int(Int(UBound(Arr) - LBound(Arr) + 1) _
* Rnd + LBound(Arr)))
If Not Dic.Exists(v) Then
Select Case UCase(v)
Case Is = "C", "D"
Dic.Add "C", "C"
Dic.Add "D", "D"
i = i + 2
Case Is = "H", "J", "K"
Dic.Add "H", "H"
Dic.Add "J", "J"
Dic.Add "K", "K"
i = i + 3
Case Else
Dic.Add v, v
i = i + 1
End Select
End If
Loop Until i >= UBound(Arr)

With Worksheets("Sheet1")
.Range("A1").Resize(i) = Application.Transpose(Dic.items)
End With
'--------------------------------------



"warren dwyer" a écrit dans le message de groupe de discussion :
(e-mail address removed)...
I need to create a large number of randomly sorted lists from a single master list (random
team order per event based on a list of teams entered for all events). Some of the entries
must remain in the same order in each list, but the remaining entries must be shuffled.

ie. Teams are A, B, C, D, E, F, G, H, J, K and L . CD and HJK must always appear in the
same order. Therefore B.CD.ME.HJK.FAGL, AF.HJK.GMLEB.CD, HJK.FL.CD.EBAGM etc are all
valid solutions.

I can create a fully random list easily, but can't find an easy way to keep the important
entries in the same order.

Cheers
Waz.


Submitted via EggHeadCafe - Software Developer Portal of Choice
Look Ma, No DataBase! Bamboo Prevalence
http://www.eggheadcafe.com/tutorial...d77-d3a00233c10a/look-ma-no-database-bam.aspx
 
J

joel

Assign the items the same random number in the 1st field and then use
second field for the order 1,2,3,.... Then sort on the two fields.
Items that are singular just keep the 2nd field empty
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top