Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 149,436 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,314 people online right now. Registration is fast and FREE... Join Now!




How to pick random numbers that aren't in sequence

 
Reply to this topicStart new topic

How to pick random numbers that aren't in sequence, picking different numbers from a group of numbersI

chevywes
31 Jan, 2008 - 08:20 AM
Post #1

New D.I.C Head
*

Joined: 24 Jan, 2008
Posts: 44

I have 8 groups of people and 4 locations were they can meet. I want 2 groups to meet together at each location once a month. I want each group to meet with one another at some point. I figured out all the possible combinations from 1 to 8 and it adds up to 28 combinations. I would like to make a six month schedule at least, longer if possible. So if I group 1 and 2 meet together in one month then they shouldn't meet together again until they have met with all the other groups.
eg: if group 1 & 2 meet and group 3 & 4 meet and group 5 & 6 meet and group 7 & 8 meet then next month they should all meet with a different. I'm trying to pick these groups randomly. In my code I have 28 combinations, so if group 1 & 2 meet then I wouldn't use the combination of 1 or 2 for the same month because one group can't be in two places at the same time.

So the first month I randomly pick any two groups to meet together from my combination of 1 to 28. How do I eliminate all the possible combinations of 1 & 2 so I don't pick them again and just use the rest of my combinations.

Please excuse the length of this post. Thanks for all your help
wes

CODE

a = "1/2" : b = "2/3" : c = "3/4" : d = "4/5" : e1 = "5/6" : f = "6/7" : g = "7/8" : h = "1/3" : i = "2/4"
        j = "3/5" : k = "4/6" : l = "5/7" : m = "6/8" : n = "1/4" : o = "2/5" : p = "3/6" : q = "4/7" : r = "5/8"
        s = "1/5" : t = "2/6" : u = "3/7" : v = "4/8" : w = "1/6" : x = "2/7" : y = "3/8" : z = "1/7" : aa = "1/8"
        bb = "2/8"

        '''' generating list for Jan

        jan1 = "" : jan2 = "" : jan3 = "" : jan4 = ""
        kk = "" : jj = "" : ii = 0
        Do
            dupes = False
            kk = Int(Rnd() * 28) + 1
            kk = kk + 96
            jj = Chr(kk)

            If jj = "a" Then
                jan1 = "1/2"
            ElseIf jj = "b" Then
                jan1 = "2/3"
            ElseIf jj = "c" Then
                jan1 = "3/4"
            ElseIf jj = "d" Then
                jan1 = "4/5"
            ElseIf jj = "e" Then
                jan1 = "5/6"
            ElseIf jj = "f" Then
                jan1 = "6/7"
            ElseIf jj = g Then
                jan1 = "7/8"
            ElseIf jj = "h" Then
                jan1 = "1/3"
            ElseIf jj = "i" Then
                jan1 = "2/4"
            ElseIf jj = "j" Then
                jan1 = "3/5"
            ElseIf jj = "k" Then
                jan1 = "4/6"
            ElseIf jj = "l" Then
                jan1 = "5/7"
            ElseIf jj = "m" Then
                jan1 = "6/8"
            ElseIf jj = "n" Then
                jan1 = "1/4"
            ElseIf jj = "o" Then
                jan1 = "2/5"
            ElseIf jj = "p" Then
                jan1 = "3/6"
            ElseIf jj = "q" Then
                jan1 = "4/7"
            ElseIf jj = "r" Then
                jan1 = "5/8"
            ElseIf jj = "s" Then
                jan1 = "1/5"
            ElseIf jj = "t" Then
                jan1 = "2/6"
            ElseIf jj = "u" Then
                jan1 = "3/7"
            ElseIf jj = "v" Then
                jan1 = "4/8"
            ElseIf jj = "w" Then
                jan1 = "1/6"
            ElseIf jj = "x" Then
                jan1 = "2/7"
            ElseIf jj = "y" Then
                jan1 = "3/8"
            ElseIf jj = "z" Then
                jan1 = "1/7"
            ElseIf jj = "{" Then
                jan1 = "1/8"
            ElseIf jj = "|" Then
                jan1 = "2/8"
            End If
        Loop Until dupes = False


This post has been edited by PsychoCoder: 31 Jan, 2008 - 08:48 AM
User is offlineProfile CardPM
+Quote Post

Jayman
RE: How To Pick Random Numbers That Aren't In Sequence
31 Jan, 2008 - 01:55 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,298



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Each time you assign a pair of groups for each month you will need to compare them to those assigned the previous months. If the groups have already met then you will have to perform the random calculation again.

Basically you will keep performing the random function and checking until a pair is generated that have not met before.
User is online!Profile CardPM
+Quote Post

baavgai
RE: How To Pick Random Numbers That Aren't In Sequence
31 Jan, 2008 - 02:41 PM
Post #3

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,274



Thanked: 135 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

My Contributions
Use an array. Seriously, you absolutely need an array to do this in any kind of reasonable way.

Better yet, get this all into an ArrayList. Google it up. If you can randomly pick from a list of choices, then you can eliminate the choice you picked from the list. That's the answer, really. Now, all you have to do is code.

Hope this helps.

User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 12:10PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month