On Mon, Oct 20, 2008 at 7:00 AM, Sean Owen <[EMAIL PROTECTED]> wrote:

> ..
> If you're looking for a good value to initialize some kind of "max"
> variable to, try {Float,Double}.NEGATIVE_INFINITY. It is smaller than
> every actual float/double.


Try using the first element that you are comparing to!

Anything else is pretty dangerous.


> To generate a truly random float or double, try
>
> Double.longBitsToDouble(Random.nextLong())


NOOOOO!!

This will not be the uniformly distributed number that you are probably
wanting.  It will have a very strange distribution that includes
denormalized numbers, NAN's, and infinities of various kinds.

Try gen.nextDouble() where gen is a math.Random or better random number
generator.

Even (double) Random.nextLong() / Long.MAX_VALUE would be better.


-- 
ted

Reply via email to