mattw112 Posted December 1, 2008 Share Posted December 1, 2008 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 More sharing options...
PsaltyDS Posted December 1, 2008 Share Posted December 1, 2008 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 More sharing options...
BrettF Posted December 1, 2008 Share Posted December 1, 2008 Very nice... Works a charm Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
mattw112 Posted December 1, 2008 Author Share Posted December 1, 2008 (edited) 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 December 1, 2008 by mattw112 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now