#! /bin/sh
TIME=`date "+%s"`
COUNT=${1:-1024}
if [ $# -gt 1 ]
then
	echo "Usage: $0 [ count ]" 1>&2
	exit 1
fi
for i in `seq 1 1 $COUNT`
do
	./rand_sample
	NEWTIME=`date "+%s"`
	if expr \( $TIME + 60 \) \< $NEWTIME > /dev/null
	then
		TIME=$NEWTIME
		echo "$i iterations (out of $COUNT)" 1>&2
	fi
done | python random_bits.py
NEWTIME=`date "+%s"`
SEC=`expr $NEWTIME - $TIME`
echo -n "Time used: "
if [ $SEC -ge 3600 ]
then
	HRS=`expr $SEC / 3600`
	SEC=`expr $SEC % 3600`
	if [ $SEC -ne 0 ]
	then
		echo -n $HRS "hours, "
	else
		echo -n $HRS "hours"
		exit 0
	fi
fi
if [ $SEC -ge 60 ]
then
	MIN=`expr $SEC / 60`
	SEC=`expr $SEC % 60`
	if [ $SEC -ne 0 ]
	then
		echo -n $MIN "minutes and "
	else
		echo -n $MIN "minutes"
		exit 0
	fi
fi
if [ $SEC -eq 1 ]
then
	echo "1 second"
else
	echo "$SEC seconds"
fi
exit 0
