> +## -------------------- triangular -------------------- > + > + def triangular(self, low, high, mode): > + """Triangular distribution. > + > + Continuous distribution bounded by given lower and upper limits, > + and having a given mode value in-between. > + > + http://en.wikipedia.org/wiki/Triangular_distribution > + > + """ > + u = self.random() > + c = (mode - low) / (high - low) > + if u > c: > + u = 1 - u > + c = 1 - c > + low, high = high, low > + return low + (high - low) * (u * c) ** 0.5 > +
Would it be worth having default values on the parameters for this? def triangular(self, low=0, high=1, mode=None): u = self.random() if mode is None: c = 0.5 else: c = (mode - low) / (high - low) if u > c: u = 1 - u c = 1 - c low, high = high, low return low + (high - low) * (u * c) ** 0.5 At the very least, supporting mode=None would be convenient when you want a symmetric triangular distribution - having to calculate the median, pass it in as the mode, then have the function reverse that to get 0.5 seems a little wasteful. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --------------------------------------------------------------- http://www.boredomandlaziness.org _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com