By multiplying the random number which is between 0 and 1 by 5 we make it a random number between 0 and 5 for example 3 1841.
Making random number with math and math floor.
Because floor is a static method of math you always use it as math floor rather than as a method of a math object you created math is not a constructor.
So you can get a random number from 10 to 15 for example.
Returns a random integer from 1 to 100 try it yourself a proper random function as you can see from the examples above it might be a good idea to create a proper random function to use for all random integer purposes.
Function randomintfrominterval min max return math floor math random max min 1 min.
The random method returns a random number from 0 inclusive up to but not including 1 exclusive.
Multiplying that by 256 will give you a number in the range 0 inclusive through 256 exclusive but still floating point.
Math floor math random 100 1.
The max min 1 is the logic that creates the range.
Math e having a value as 2 718281828459045.
Taking the floor of that number will give you an integer between 0 and 255 both inclusive.
Math pi having a value as 3 141592653589793.
Math random will give you a floating point number between 0 inclusive and 1 exclusive.
A number representing the largest integer less than or equal to the specified number.
The math random function returns a floating point pseudo random number in the range 0 to less than 1 inclusive of 0 but not 1 with approximately uniform distribution over that range which you can then scale to your desired range.
Math floor math random max min 1 is generating a whole number between the range of 0 to 8.
What it does extra is it allows random intervals that do not start with 1.
When you add the min at the end you are adding the 2 to your range and end up with a random number from 2 to 10.
Math floor x parameters x a number.