Created
April 4, 2016 13:24
-
-
Save ciscoslot/d2d57b351e4852d5e03a30663fdcd87b to your computer and use it in GitHub Desktop.
Unity Gaussian Random
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public static class GaussianRandom | |
{ | |
public static float generateNormalRandom(float mu, float sigma) | |
{ | |
float rand1 = Random.Range(0.0f, 1.0f); | |
float rand2 = Random.Range(0.0f, 1.0f); | |
float n = Mathf.Sqrt(-2.0f * Mathf.Log(rand1)) * Mathf.Cos((2.0f * Mathf.PI) * rand2); | |
return (mu + sigma * n); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment