#!/usr/local/bin/perl @schedule = ([name1,name2], [name3,]); @names = (name1, name2, name3, name4); for $name(@names) { $signedup{$name} = 0; } for ($i=0; $i < @schedule; $i++) { $signedup{$schedule[$i][0]} ++; $signedup{$schedule[$i][1]} ++; } srand 611-2003; for ($i=0; $i < @schedule; $i++) { for $j (0,1) { if ( not defined $schedule[$i][$j] ) { do { $pick = @names[rand @names]; } while ($signedup{$pick} >= 2 or ($j == 1 and ($pick eq $schedule[$i][0]))); $schedule[$i][$j] = $pick; $signedup{$pick} ++; } } } for ($i=0; $i < @schedule; $i++) { print ("lecture ", $i+2, ": ", $schedule[$i][0], ", ", $schedule[$i][1], "\n"); }