This content has been marked as final.
Show 3 replies

1. Re: how to get a random gaussian float?
807598 Oct 22, 2006 9:33 PM (in response to 807598)The code is available from http://laseeb.isr.ist.utl.pt/sw/JDEAL/
Under the heading "How can I get it" there is a link with the text "download".
This links to a .zip file containing the source.
This is from the source of pt.laseeb.util.RNG
So it looks like using Random and casting the double to a float is aspublic class RNG extends Random { private static java.util.Random random; private static long randomSeed; static { randomSeed=System.currentTimeMillis(); random=new java.util.Random(randomSeed); } // other stuff /** * Generates a random float from a Gaussian distribution with the specified * deviation. * <p> * @param dev the desired deviation. * @return a random float from a Gaussian distribution with deviation * <code>dev</code>. */ public static float gaussianFloat(float dev) { return (float)random.nextGaussian()*dev; } // other stuff }
good as it gets.
[Edit] Where does this [nobr] business come from? 
2. Re: how to get a random gaussian float?
807598 Oct 23, 2006 12:28 AM (in response to 807598)ok. does anyone know how to scale these numbers so that they span the entire range of float values?
ie so that the max value is the max float value and the min value is the min float value.
thanks.... 
3. Re: how to get a random gaussian float?
807598 Oct 23, 2006 1:05 AM (in response to 807598)In general if you have a number x in the range (a,b) and you apply a
linear scaling x > c+(xa)*(dc)/(ba) you'll end up with a number in
the range (c,d). If a number of xvalues with a given distribution are
transformed in this way the resulting distribution will have a similar
"shape".
Care will be needed in implementing this because of the value of
(dc) when you are scaling up to the full float range.
So for instance if the xvalues were originally uniformly distributed the
transformed values will be as well. Likewise if the original values are
(rather roughly) gaussian, the transformed values will be as well. I
say "rather roughly" because values obtained from Random's
nextGaussian() will, in general, occupy the entire range of double.
If you cast the result of nextGaussian() you don't have to scale the
result. In fact the problem (if there is one) is the reverse: some of the
floats obtained this way will be infinite. This problem won't occur in
practice unless the mean and/or sd of your gaussian distribution is
very, very, very big.