Hearing Dog Tool - Adding Randomness
I started by writing a function to pick a random number between two numbers given as arguments.
function get_random( $max, $min)
// return a random number between $min and $max
return (Math.floor((Math.random() % 1) * $diff) + $min);
Then I simply called this function with appropriate arguments (120 and 30) in my do_alarm function where I had previously just defined a number to use as seconds to wait.
// mark alarm as set
// determine time to wait in seconds
// wait for time to be up & sound alarm
setTimeout("sound_alarm()", (wait_secs * 1000))
Now the program alarm is set to a random interval, although it otherwise works exactly the same as my last revision. You can view all the code and try out a working example here.
This site needs an editor - click to learn more!
You Should Also Read:
Hearing Dog Training - setTimeout()
Editor's Picks Articles
Top Ten Articles
Content copyright © 2021 by Julie L Baumler. All rights reserved.
This content was written by Julie L Baumler. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.