Last active
February 27, 2022 03:21
-
-
Save tildebyte/f79e6cac6e00764ae32c0ee3ab6dbd0f to your computer and use it in GitHub Desktop.
ES6 utility functions for Codepen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Return a value from a given range, which avoids zero, within a given tolerance. | |
function avoidZero(range, tolerance) { | |
// Return a random value in the range from `-range` to strictly less than | |
// `range`, excluding the inner range +/-`tolerance` (and, logically, zero as | |
// well). | |
let value = _.random(-range, range) | |
while (-tolerance < value && value < tolerance) { | |
value = _.random(-range, range) | |
} | |
return value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment