#!/usr/local/bin/perl5.00502
#	rndarg
#	by Paul Balyoz
#	Domtools release 1.5.0
#
#	Output all command-line arguments passed in, but in a random order,
#	one argument output per line.
#
# Copyright (C) 1993-2000 Paul A. Balyoz <pab@domtools.com>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

#	$DEBUG=1;			# uncomment for debugging output

	local($i,$pos);
	local(@argp,$tmpp);

# Seed random number generator in a fairly good way

	srand(time | $$<<5);

# Create modifiable list of argument strings

	for ($i=0; $i<=$#ARGV; $i++) {
		$argp[$i] = $ARGV[$i];
	}

# Randomly rearrange argument strings

	for ($i=0; $i<=$#ARGV; $i++) {
		$pos = int(rand($#ARGV+1));
		if ($DEBUG) {
			print "$i swap with $pos\n";
		} else {
			$tmpp = $argp[$pos];
			$argp[$pos] = $argp[$i];
			$argp[$i] = $tmpp;
		}
	}

# Now print the randomized arguments each on separate lines

	for ($i=0; $i<=$#ARGV; $i++) {
		print "$argp[$i]\n";
	}

	exit 0;
