Q
PRO
Quiet
asked

Expert
Kelish Rai answered
Hi quiet,
You're absolutely right .
In Java, Math.random() returns a value from 0.0 (inclusive) to 1.0 (exclusive). So:
Math.random() * 10 // gives a value from 0.0 to less than 10.0
Math.random() * 10 + 1 // gives a value from 1.0 to less than 11.0
So the correct range for Math.random() * 10 + 1 is 1.0 (inclusive) to less than 11.0 (exclusive).
If you have more questions, I am here to help.
Java
This question was asked as part of the Learn Java Basics course.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer
