class CustomRandom {
	float[] gausSet = {0.01f, 0.01f, 0.01f, 0.05f, 0.3f, 0.4f, 0.3f, 0.05f, 0.01f, 0.01f};
	
	public CustomRandom() {
		
	}
	
	public void useDistribution(float[] rset) {
		gausSet = rset;
	}
	
        float getRandom(int rVal) {
            return getRandom(0, rVal);
        }
        
float getRandom(int rMin, int rMax) {


  int range = rMax - rMin;
  float rangeScale = (float)range / (float)gausSet.length;
  
  // loop through this test until we succeed
  while (true) {
      // generate a test number in our range
      float testRandom = random(rMin, rMax);
  
      // see if this is under our curve
      
      // scale our random number down to our gaussian scale
      float gausScale = (testRandom / rangeScale);
      
      // figure out which number this lies between and if that averaged
      // number is under the curve
      float leftProbability = gausSet[(int)gausScale];
      float rightProbability = 0.0;
      if ((int)gausScale + 1 == gausSet.length) {
        rightProbability = gausSet[gausSet.length - 1];
      } else {
        rightProbability = gausSet[(int)gausScale + 1];
      }
      
      float probDiff = 0.0;
     // if (int(gausScale) > 4 ) {
     //    probDiff = leftProbability - rightProbability;
     // } else {
         probDiff = rightProbability - leftProbability;
     // }
      
      probDiff = leftProbability + (probDiff * ( gausScale - (float)((int)gausScale)));
      
      if (random(0, 1) < probDiff) {
          return testRandom;
      }
      
      
      
  }
 
    
}
}
