+ Reply to Thread
Results 1 to 6 of 6

Random Pair Generator Explanation

  1. #1
    Registered User
    Join Date
    12-30-2022
    Location
    TN, USA
    MS-Off Ver
    2019
    Posts
    2

    Random Pair Generator Explanation

    Hello,
    I am trying to code a random drawing for a running order in a bird dog field trial. There are some stipulations you should know: Draw 2 dogs at a time, The same person (dog handler) could have multiple dogs entered into the trial, so each dog handler can only be drawn once per pairing. Male and female dogs shouldn't be paired together. I want to randomly select 2 handlers and 2 dogs to make a brace and do that until i run out of entries.

    There is a post from 2018 that basically had everything I needed in it and i added my data.

    Can someone help me to understand the code that is in the spreadsheet below? I feel like it does everything i want it to do but i have to be able to explain it thoroughly in order to implement this random draw via computer instead of bingo balls.

    Random Pair Drawing.xlsx

  2. #2
    Forum Contributor Gregor y's Avatar
    Join Date
    10-24-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2010 32-Bit
    Posts
    276

    Re: Random Pair Generator Explanation

    By Columns
    B: dog names (it is assumed that these are not duplicated, add 0,1,2,.../whatever to make this assumption true)
    C: dog gender
    D: handler names
    E: paired dog name from K
    F: random number aka bingo ball

    H: dog names from B re-written in the order of F
    I: the gender of H
    J: the handler of H
    K: the first dog in H with the same gender from I and a different handler in J but hasn't been used previously in K

    Notes on K:
    These are pairs because of the "first" property of the lookup, the first with a different handler prevents the dog from matching itself as well as another dog by the same handler; then later on when you get to that dog in the list its "first" which hasn't previously been used is the dog to which paired with it earlier on in the list.

    When only f gender dogs can match with f dogs, and you have three of them, then one will always be #N/A; pair her with the #N/A m dog. Similar situations can happen by handler name as well depending on who gets paired first(just recalculate the spreadsheet to get a new order until this problem goes away).
    Last edited by Gregor y; 02-20-2023 at 09:50 PM. Reason: clarify

  3. #3
    Registered User
    Join Date
    12-30-2022
    Location
    TN, USA
    MS-Off Ver
    2019
    Posts
    2

    Re: Random Pair Generator Explanation

    Thank you. I feel pretty confident in explaining the columns. I want to further understand the Index function and how it is being used to do the random drawings.

    Is there a resource i could be pointed towards to do that?

    Thanks

  4. #4
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,531

    Re: Random Pair Generator Explanation

    One resource to use is the Evaluate Formula feature on the Formulas tab.
    Let us know if you have questions about any of the steps in the evaluation of the formula.
    Last edited by JeteMc; 02-27-2023 at 11:16 PM. Reason: edited text
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  5. #5
    Forum Contributor Gregor y's Avatar
    Join Date
    10-24-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2010 32-Bit
    Posts
    276

    Re: Random Pair Generator Explanation

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    The random part is in F and H
    F is the pick a random number, which H can then sort smallest to largest.

    The INDEX() function does basically what its name suggests, it gives you back the item in a list or a table that you asked for.
    Index(ListOfStuff,15) gives you the 15th item from ListOfStuff
    Index(TableOfStuff,14,2) gives you the 14th item in the 2nd column from TableOfStuff

    The MATCH() function finds what you're looking for and tells you where it is in the list
    Match(FindThis,ListOfStuff,0) will tell you the Nth spot in ListOfStuff where it found FindThis (note we used 0 so that we get an #N/A when it isn't in the list)

    putting these two together
    Index(ListOfStuff,Match(FindThis,ListOfStuff,0),AnotherColumn) will give you the adjacent data in AnotherColumn when you don't know where FindThis is in the list.

    so for the H formula it's a little trickier because the two lists are different and there's two more players SMALL() and ROW()

    ROW(address) gives you the row number of the first cell in address
    Row(1:1) is the row number for the whole row of row one aka 1
    likewise Row(2:2) is 2, you'd get the same row number with A2, but 2:2 is probably a little more monkey proof.

    SMALL(ListOfStuff,N) is a cool one that I had to lookup, it gives you the Nth smallest one in the list
    Small(ListOfStuff,Row(1:1)) gives you the smallest in the ListOfStuff
    likewise Small(ListOfStuff,Row(2:2)) gives you the second smallest

    pulling it togeather
    Index(ListOfNames,Match(Small(ListOfRandom,Row(N:N)),ListOfRandom,0)) would give you the entry from ListOfNames which aligns with the Nth smallest entry in ListOfRandom

    That being said taking a look at the other use of Index/Match as in seen in K
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    the tricky part here is you have something like
    Index(ListOfNames,Match(FindAOne,ListOfOnesAndZeros,0))
    where the ListOfOnesAndZeros are true/false statements based on:
    (same gender) and (different handler) and (hasn't been used yet)
    evaluated for each item in the list, then you match to the first One aka true entry to get the Nth match that fits the criteria, then index into the ListOfNames to get the name.
    Last edited by Gregor y; 02-27-2023 at 11:23 PM.

  6. #6
    Forum Contributor Gregor y's Avatar
    Join Date
    10-24-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2010 32-Bit
    Posts
    276

    Re: Random Pair Generator Explanation

    Quote Originally Posted by Gregor y View Post
    just recalculate the spreadsheet to get a new order until this problem goes away
    I suppose there could be the possibility that no solution exists as well
    Dog Gender Handler Pair
    DogA M Bob DogB
    DogB M Sam DogA
    DogC M Jeff #N/A
    DogD M Jeff #N/A
    DogE M Jeff #N/A
    DogF M Jeff #N/A

    It can be improved, but Jeff is always going to have two dogs out
    Dog Gender Handler Pair
    DogA M Bob DogC
    DogC M Jeff DogA
    DogB M Sam DogD
    DogD M Jeff DogB
    DogE M Jeff #N/A
    DogF M Jeff #N/A

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Random number generator not always generating random numbers
    By Murman01 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-03-2021, 05:29 PM
  2. Help to pick two random names from a list to pair up please.
    By TrainerJ in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-04-2021, 06:13 AM
  3. [SOLVED] Random Pair Generation with Multiple Criteria (index/match)
    By vankmj in forum Excel General
    Replies: 11
    Last Post: 05-21-2020, 11:35 AM
  4. Replies: 6
    Last Post: 02-20-2019, 12:47 AM
  5. Replies: 5
    Last Post: 06-21-2013, 10:40 AM
  6. Help create code to pair like items at random
    By SAFD1450 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-30-2011, 01:03 PM
  7. Random Name Generator
    By Smeeg in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-03-2006, 11:30 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1