+ 2
How can i import math library with the random and floor function
I created a small game which need to import random number
2 Answers
+ 5
If your talking about Javascript, then there is no need to import anything. Its inbuilt.
You can access it by Math.
âRandom Number
There is a function random in Math.
Like this,
var num = Math.random()
This produces a random decimal between 0 and 1.
You can multiply that number with 50, if you want to have a random number till 50.
For ex.
var num = Math.random() * 145
This produces a random number between 0 and 145. This code may produce 10.2828, 78.234, 18.23, 90.36, 144.5, 1.1, etc,etc....
PLEASE ASK IF YOU HAVE ANY DOUBTS
0
I used the same method you stated above but there was an error in the console