Returns function which produces a random number of seconds, with a unit of milliseconds. Maximum value is exclusive. Use secondsMs to return a random value directly, or secondsMsSource to return a function.
Maximum seconds, or options.
Milliseconds
// Create functionconst f = secondsMsSource(5000);// Produce a valueconst value = f(); Copy
// Create functionconst f = secondsMsSource(5000);// Produce a valueconst value = f();
// Random milliseconds between 1000-4999const value = secondsMsSource({ max:5, min:1 })();// Note the extra () at the end to execute the function Copy
// Random milliseconds between 1000-4999const value = secondsMsSource({ max:5, min:1 })();// Note the extra () at the end to execute the function
It's a very minor function, but can make code a little more literate:
// Random timeout of up to 5 secondssetTimeout(() => { ...}, secondsMsSource(5)); Copy
// Random timeout of up to 5 secondssetTimeout(() => { ...}, secondsMsSource(5));
Returns function which produces a random number of seconds, with a unit of milliseconds. Maximum value is exclusive. Use secondsMs to return a random value directly, or secondsMsSource to return a function.