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
Well you could use one more random, which would decide if you multiply by 1 or (-1)? if random >0.5 (first_random *1) else (first_random*(-1))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With