Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Math.random() returns a floating point number from 0 up to but not including 1. For example:
- /*
- > Math.random()
- 0.2625259844878184
- > Math.random()
- 0.06513541210374607
- > Math.random()
- 0.5629554153276711
- */
- /*
- but normally you will want a larger number. To do this you can multiply Math.random() by a number. If we wanted numbers between 0 & up to but not including 100:
- > Math.random() * 100
- 26.25259844878184
- > Math.random() * 100
- 6.513541210374607
- > Math.random() * 100
- 56.29554153276711
- */
- /*
- Often you will want a whole number, for that we can use Math.floor() which will strip off the numbers after the decimal:
- */
- Math.floor( Math.random() * 100 );//output any numbers 0,1,2,3,4,5 ...... 97,98,99. 99 ONLY
- /*
- If you wanted numbers between 1 & 100 then you would need to + 1. So it becomes
- */
- Math.floor( Math.random() * 100 ) + 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement