Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Java SDK has good implementation Random.nextGaussian (taken from <a href="http://download.oracle.com/javase/1.4.2/docs/api/java/util/Random.html#nextGaussian" rel="nofollow">http://download.oracle.com/javase/1.4.2/docs/api/java/util/Random.html#nextGaussian</a>())</p> <p>I hope it is rather clear how to parse from java source to c#</p> <pre><code>synchronized public double nextGaussian() { if (haveNextNextGaussian) { haveNextNextGaussian = false; return nextNextGaussian; } else { double v1, v2, s; do { v1 = 2 * nextDouble() - 1; // between -1.0 and 1.0 v2 = 2 * nextDouble() - 1; // between -1.0 and 1.0 s = v1 * v1 + v2 * v2; } while (s &gt;= 1 || s == 0); double multiplier = Math.sqrt(-2 * Math.log(s)/s); nextNextGaussian = v2 * multiplier; haveNextNextGaussian = true; return v1 * multiplier; } } </code></pre> <p><strong>UPDATE:</strong> How I've made shift of median:</p> <pre><code>public static float gaussianInRange(float from, float mean, float to) { if( !(from &lt; mean &amp;&amp; mean &lt; to) ) throw new IllegalArgumentException(MessageFormat.format("RandomRange.gaussianInRange({0}, {1}, {2})", from, mean, to)); int p = _staticRndGen.nextInt(100); float retval; if (p &lt; (mean*Math.abs(from - to))) { double interval1 = (_staticRndGen.nextGaussian() * (mean - from)); retval = from + (float) (interval1); } else { double interval2 = (_staticRndGen.nextGaussian() * (to - mean)); retval = mean + (float) (interval2); } while (retval &lt; from || retval &gt; to) { if (retval &lt; from) retval = (from - retval) + from; if (retval &gt; to) retval = to - (retval - to); } return retval; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload