public static double Sample(double shape, double scale, double lowerBound, double upperBound) { double sample; do { sample = Gamma.Sample(shape, scale); } while (sample < lowerBound || sample > upperBound); return(sample); }
public static double Sample(Gamma gamma, double lowerBound, double upperBound) { double sample; do { sample = gamma.Sample(); } while (sample < lowerBound || sample > upperBound); return(sample); }
public static double Sample(Gamma gamma, double lowerBound, double upperBound) { if (gamma.IsUniform()) { return(Rand.UniformBetween(lowerBound, upperBound)); } bool useQuantile = (gamma.Shape == 1); if (useQuantile) { return(GetQuantile(gamma, lowerBound, upperBound, Rand.UniformBetween(0, 1))); } else { double sample; do { sample = gamma.Sample(); } while (sample < lowerBound || sample > upperBound); return(sample); } }