# memifperm.awk, 11 Apr 04
#

function rand_subject()
{
printf("") > TEMP_FILE
for (s in subj_info)
   print subj_info[s] >> TEMP_FILE
close(TEMP_FILE)

print "SUBJECT"
system("sort -g < " TEMP_FILE)

delete subj_info
}

BEGIN {
	TEMP_FILE=systime() ".tmp"
	seen_subject=0
	}

$0 == "SUBJECT" {
	if (seen_subject == 0)
	   seen_subject=1
	else
	   rand_subject()
	next
	}

	{
	subj_info[$1]=$0
	next
	}

END {
	rand_subject()
	system("rm " TEMP_FILE)
	}
