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.
Example: Random milliseconds between 0..4999
// Create function constf = secondsMsSource(5000); // Produce a value constvalue = f();
Example: Options can be provided
// Random milliseconds between 1000-4999 constvalue = secondsMsSource({ max:5, min:1 })(); // Note the extra () at the end to execute the function
Remarks
It's a very minor function, but can make
code a little more literate:
// Random timeout of up to 5 seconds setTimeout(() => { ...}, 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.
Example: Random milliseconds between 0..4999
Example: Options can be provided
Remarks
It's a very minor function, but can make code a little more literate: