/*
   ###########################################################################
   This function returns a random time string in the 00 to 24h range.
   The returned time string will resemble: '12:34:05.678901234567890'

   ARGUMENT:
   Symbols (NOT case-sensitive):
       ' '   = Use blank spaces as HMS separators    ('01 02 33')
       ':'   = Use colons (:) as HMS separators      ('01:02:33') = Default
       'h'   = Use (h) symbol for hrs ('01h')
       'hm'  = Use (hm) symbols as hrs,min ('01h 02m')
       'hms' = Use (hms) symbols as hrs,min,sec ('01h 02m 33s')

   The decimals, if used in the seconds part, can be set for practicality and
   only works in hms mode.
   ###########################################################################
*/

   function Random_Time_Str ($Symbols=':', $Decimals=0)
{
   $decimals = IntVal(trim($Decimals));

   $symbols = StrToUpper(substr(trim($Symbols),0,3));
              if (
                  $symbols <> ''  and $symbols <> ':'
              and $symbols <> 'H' and $symbols <> 'HM'
              and $symbols <> 'HMS'
                 )
                 {$symbols = ':';}

// ------------------------------------------
// Construct random 'HHmmss' time string.

   $HH = Random_Int(0, 23); // Random hours
   $mm = Random_Int(0, 59); // Random minutes
   $ss = Random_Int(0, 59); // Random seconds

// -------------------------------------------
// Generate a string of random decimals digits
// to be attached to the seconds part.

   $dd = '';  for ($i=0;  $i < $decimals;  $i++)  {$dd .= Random_Int(0,9);}

// -----------------------------------
// Format the generated time elements.

   $HH = SPrintF("%02d", $HH);
   $mm = SPrintF("%02d", $mm);
   if ($ss < 10) {$ss = "0$ss";}

   $h = 'h'; $m = 'm'; $s = 's';
   if ($symbols == ':')   {$HHmmss = "$HH:$mm:$ss.$dd";}
   if ($symbols == 'H')   {$HHmmss = "$HH$h";}
   if ($symbols == 'HM')  {$HHmmss = "$HH$h $mm$m";}
   if ($symbols == 'HMS') {$HHmmss = "$HH$h $mm$m $ss.$dd$s";}

   if ($symbols == '')    {$HHmmss = "$HH $mm $ss.$dd";}

   $HHmmss = RTrim($HHmmss, '.');
   return Str_Replace('.s', 's', $HHmmss);

} // END of  Random_Time_Str (...)