Im studying opengles. I want to know how can i generate between -1 to 1. Thats because opengl normalized device coordinates is only between -1 and 1. Some mentioned that random float is only between 0.0 and 0.9999999.
here is my code
points.addParticles(new GeoPoint(-random.nextFloat(),random.nextFloat(),random.nextFloat()),180);
Thats for x,y,z and random color.
I just want to generate random points inside the screen with random location.
Well Random.nextFloat
gives a value greater than or equal to 0, and less than 1 - i.e. a range of [0, 1). So to map that to a range of [-1, 1)
you just need to multiply by 2 and subtract 1.
float value = random.nextFloat() * 2 - 1;
In general, to get a value in the range [x, y)
you would use
random.nextFloat() * (x - y) + x
See more on this question at Stackoverflow