lundi 22 décembre 2014

Java Random.nextGaussian between 0 and 1

I'm working on an image editor and I'm about to implement filters. I decided to go with some kind of blur or noise.


Anyway, I decided I wanted a uniform filter so I read up on Random.nextGaussian().


However, since I'm working with RGB values that range from 0 to 255. How can I scale this random double value to fit within 0 and 255?


The random value returned by the nextGaussian() can range from -1 to 1 I believe.


So, I want to preserve the relative difference between the random values. "Scale" or "move the number range" if that makes sense.


I know it's possible but I can't figure it out. Thanks in advance.


Essentially, I need it to be a number between 0 and 1.





Aucun commentaire:

Enregistrer un commentaire