#!/usr/bin/perl

# $result = randfloat( $low, $high )
# $result = randfloat( $high )
# $result = randfloat
#    Return a floating-point value between $low and $high.
#    Return a floating-point value between 1 and $high.
#    Return a floating-point value between 0 and 1.
sub randfloat {
    my ( $low, $high ) = @_;

    # The default alternatives.
    $high = 0 unless defined $high;
    $low  = 1 unless defined $low;

    # Make sure that they're in order.
    ($low,$high) = ($high,$low) if $low > $high;

    return $low + rand ( $high - $low );
}

# Pick a portion of an hour.
$minute_range = randfloat( 0, 60 );

# Since it is floating point, we can break it up into a
# finer resolution than just minutes:
$minutes      = int( $minute_range );
$second_range = ($minute_range - $minutes) * 60;
$seconds      = int( $second_range );
$thousandths  = int( 1000 * ($second_range - $seconds) );

printf "time picked: %02d:%02d.%03d\n", $minutes, $seconds, $thousandths;
