Set the length of random

Hello, I’ve a problem at js. How can I set the length of Math.random?

Hey @eray6421 – can you tell me more about what you mean by “set the length”? Math.random() will always return a value between 0 and 1 – are you interested in rounding that number to a lower precision (i.e., 0.692 instead of 0.6918536114538683) or are you interested in generating a random number from with a range (such as randomly picking a number between 10 and 30, for example)? (Or have I misunderstood the question completely, haha?)

If you are looking to get something more than 0.5293852 or 0.1488352 etc. then just do the following!

let random = Math.random() * 100;

console.log(random) // Will output any number lower than 1000 and higher than 100.
1 Like

If you want to get a random number from a to b just do let x = Math.random()*Math.abs(a-b)+a

Okay, I have found the answer. Thanks you. :slight_smile: