calculating a self.value, self.randomnum = normalvariate(x, y)

Xavier Ho contact at xavierho.com
Sat Jun 20 10:49:55 EDT 2009


>
> def __int__(self, x, y):
>     x = -1
>    while not 0 <= x <= 100:
>        x = normalvariate(x, y)
>    # do other stuff
>
> That is the correct way to truncate a normal distribution.
>
>
Thanks for the response. But why would you set the mean to -1 to begin?



>
> x = max(0, min(100, normalvariate(x, y)))
>
>
That is an awesome way of shorthanding clamp.

Best regards,

Ching-Yun "Xavier" Ho, Technical Artist

Contact Information
Mobile: (+61) 04 3335 4748
Skype ID: SpaXe85
Email: contact at xavierho.com
Website: http://xavierho.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090621/b5ea85b6/attachment.html>


More information about the Python-list mailing list