0

I need a random float value between 0 and 100.

Easiest way to do this would be

Random generator = new Random();
float x = generator.nextFloat() * 100;

There's only a little Problem. nextFloat() returns values in interval [0,1), but I need values from [0,1].

Anyone an idea how to solve it?

Thanks

Max Kraus
  • 137
  • 3
  • 9
  • 1
    See this answer: http://stackoverflow.com/questions/9724404/random-floating-point-double-in-inclusive-range – Keiwan May 17 '16 at 18:21
  • So random numbers between 0 and 99.99999 is not close enough? Even if you _could_, the odds of getting _exactly_ 1 are infinitesimal. – D Stanley May 17 '16 at 20:09
  • If you are doing this to get _integers_ between 0 and 100 inclusive then just multiply by 101 instead of 100. – D Stanley May 17 '16 at 20:20

0 Answers0