The easiest way to get your first requirement is to multiple some number by your divisor (like @Robo Robok said)
- input * 5 = number devisable by 5
the next step is to bound your candidate numbers, you have an upper bound and a lower bound and they may not divide evenly so you'll have to round up and down
- upper bound = floor(upper bound / 5)
- lower bound = ceiling(lower bound / 5)
That range is what you want to use with your random number
- number range = upper bound - lower bound
So, if we take the range and multiply it by the random number and multipy it by 5 you have your generator.
- random number = (ceil(number range * random number)+lower bound) * 5
Because this was a JavaScript question:
rangedRandFactory = (multiple, min, max) => {
const ceil = Math.floor(max/multiple);
const floor = Math.ceil(min/multiple);
const range = ceil - floor;
return () => ((Math.ceil(range*Math.random()))+floor) * multiple
}