Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Returns a random integer between 0 and the value sent to the function.
- This is not really a new technique but since Math.random() returns a random
- float between 0 and 1 we need to increase the range by multipling it by the
- biggest value we expect and then "flooring" it, which means it will never
- return the max value itself.
- */
- function get_random_number(max) {
- return Math.floor(Math.random() * max);
- }
- console.log("Random number ->", get_random_number(25));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement