Randomizing the hands can be tricky when trying to draw the hands. Once the hour and minute values are acquired, the form must be refreshed and the clock redrawn. 


begin

  randomize;   {sets randomize}

  hour := random(12) + 1;  {random(12) gets 0 - 11 so adding 1 gets 1 - 12}


  randomize; {sets randomize}


  repeat   {repeat until min = a value that is div by 5, so not 3:21 stuff}

    min := random(60);

  until ((min = 0) or (min = 5) or (min = 10) or (min = 15) or (min = 20)

      or (min = 25) or (min = 30) or (min = 35) or (min = 40)

      or (min = 45) or (min = 50) or (min = 55));


end;



The code for the Quick Clock Quizzer can be download on the Tutorial 32 page




Video:  Free Pascal Tutorial 26 - Randomizing Clock Hands - Quick Clock Quizzer - Lazarus








Previous                   Next