[Solved] Java generation a random number in a specific range?


Java possesses the function Math.random() which returns a number that varies between 0 and 1. Therefore, if you want a random number to vary between 0.5 and 1 only, you need to scale this number by half so that it only varies between 0 and 0.5, and then add this to the minimum value in your range, 0.5.

private double traction = (Math.random() * 0.5) + 0.5;

solved Java generation a random number in a specific range?