Clamp a value between the min and max values. If it is below min or above max then we set the value equal to the respective boundary.
import { clamp } from 'goodish'
console.log(clamp(100, 0, 10)) // 10
Remove any previously set seed on the random number generator
import { clearSeed } from 'goodish'
clearSeed() // Now randomized functions will use Math.random again
Calculate the greatest common divisor of two numbers
import { greatestCommonDivisor } from 'goodish'
console.log(greatestCommonDivisor(18, 12)) // 6
Calculate the lowest common multiple of two numbers
import { lowestCommonMultiple } from 'goodish'
console.log(lowestCommonMultiple(6, 8)) // 24
Simple seedable Psuedo random number generator
Returns a random float between min and max.
import { random } from 'goodish'
console.log(random()) // value between 0 and 1
console.log(random(0, 100) // value between 0 and 100
@param min
@param max
Returns a random integer between the min and max values.
import { randomInt } from 'goodish'
console.log(randomInt(0, 100)) // Some integer between 0 and 100
Set the seed for our prng and switch to a simple, seedable prng
import { randomInt, setSeed } from 'goodish'
setSeed(11)
randomInt(1, 100) // always 44
Round a number to the specified number of digits
import { toFixedNum } from 'goodish'
console.log(toFixedNum(3.14159, 2)) // 3.14
Wrap the value within these bounds. More explanation of the idea (here)[https://en.wikipedia.org/wiki/Wrapping_(graphics)]
import { wrap } from 'goodish'
console.log(wrap(5, 1, 4)) // 2 because value exceeds the max val by 1 and wraps around from the lower boundary
Generated using TypeDoc