Jump to content

Randomize and Pair up Names


 Share

Recommended Posts

Hi,

I want to be able to take a list of names and then pair them up.

So for example I have 10 names, I want to pair up each name with someone else, not themselves. (an example with 4 names below)

Terry - Becky

Becky - Mom

Mom - Glenn

Glenn - Terry

I've found an array randomizer and display. But it only works on a 1D array.

Any ideas on how to do this?

#include <array.au3>
Local $a_num[10] = ["Terry", "Sabrina", "Becky", "Rochelle", "Doris", "Glenn", "Mom", "David", "Brian", "Shelley"]
_ArrayDisplay($a_random_num)

Func _ArrayRandomShuffle($av_array, $i_lbound = 0)
    Local $i_ubound = UBound($av_array) - 1
    Local $icc, $s_temp, $i_random
    
    For $icc = $i_lbound To $i_ubound
        $s_temp = $av_array[$icc]
        $i_random = Random($i_lbound, $i_ubound, 1)
        $av_array[$icc] = $av_array[$i_random]
        $av_array[$i_random] = $s_temp
    Next
    
    Return $av_array
EndFunc
Link to comment
Share on other sites

Hi,

I want to be able to take a list of names and then pair them up.

So for example I have 10 names, I want to pair up each name with someone else, not themselves. (an example with 4 names below)

Terry - Becky

Becky - Mom

Mom - Glenn

Glenn - Terry

I've found an array randomizer and display. But it only works on a 1D array.

Any ideas on how to do this?

#include <array.au3>
Local $a_num[10] = ["Terry", "Sabrina", "Becky", "Rochelle", "Doris", "Glenn", "Mom", "David", "Brian", "Shelley"]
_ArrayDisplay($a_random_num)

Func _ArrayRandomShuffle($av_array, $i_lbound = 0)
    Local $i_ubound = UBound($av_array) - 1
    Local $icc, $s_temp, $i_random
    
    For $icc = $i_lbound To $i_ubound
        $s_temp = $av_array[$icc]
        $i_random = Random($i_lbound, $i_ubound, 1)
        $av_array[$icc] = $av_array[$i_random]
        $av_array[$i_random] = $s_temp
    Next
    
    Return $av_array
EndFunc
#include <array.au3>

Global $a_num[10] = ["Terry", "Sabrina", "Becky", "Rochelle", "Doris", "Glenn", "Mom", "David", "Brian", "Shelley"]
_ArrayDisplay($a_num, "Input")

Global $a_result[Int(Ubound($a_num) / 2)], $i

For $n = 0 To Ubound($a_result) - 1
    $i = Random(0, Ubound($a_num) - 1, 1)
    $a_result[$n] = $a_num[$i] & " - "
    _ArrayDelete($a_num, $i)
    $i = Random(0, Ubound($a_num) - 1, 1)
    $a_result[$n] &= $a_num[$i]
    _ArrayDelete($a_num, $i)
Next

_ArrayDisplay($a_result, "Output")

Not tested 'cause I typed it on my Mac Mini...

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Hi,

This works as it pairs up each person with one another person.

For example:

Terry - Glenn

Sabrina - Rochelle

However (and I may not have adequately described this) each person does not need to be paired up with the person who is paired up with them.

So see example below:

Terry - Glenn

Sabrina - Rochelle

Glenn - Sabrina

Rochelle - Terry

So really I need the array randomized and names paired up with each other, with verification that the person isn't paired up with themselves...

I was thinking maybe just enter all the names into two arrays, verify that none of the positions in each array are the same 9if so rerandomize?), and then display the arrays in two columns next to each other? I'll see if I can do that unless you can think of a better way?

Thanks,

Terry

Edited by mattw112
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...