Last active
          October 13, 2015 08:47 
        
      - 
      
- 
        Save fuddl/4169785 to your computer and use it in GitHub Desktop. 
    Gaussian normal distribution
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | /** | |
| * Generate a random number considering gaussian normal distribution. | |
| * | |
| * @param min | |
| * The minimal value. Can be negative or positive. | |
| * | |
| * @param max | |
| * The maximal value. Should be higher then min. | |
| * | |
| * @param dis | |
| * The distribution. The higher is value is, the less likely min or max will | |
| * be directly returned. | |
| * | |
| * @return | |
| * A random number between min and max respecting the normal distribution. | |
| */ | |
| function normalRand(min, max, dis) { | |
| var dis = typeof dis !== 'undefined' ? dis : 42; | |
| var o = 0; | |
| var delta = max - min; | |
| for(var i = 0; i < dis; i++) { | |
| o += Math.random()*delta+min | |
| } | |
| o = Math.round(o / dis); | |
| return o; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment