Vincent Davis wrote:
I currently have something like this.

class applicant():
    def __int__(self, x, y):
        self.randomnum = normalvariate(x, y)
then other stuff

x, y are only used to calculate self.randomnum   and this seems to
work. But I want self.randomnum to be 0 <= randomnum <= 100. The only
way I can thing of to do this is is with a while statement and that
seems more complicated than necessary. I would really like to keep it
on one line. How would I do that?

Thanks
Vincent Davis

There are at least two interpretations to your requirement, both of which change the distribution. So you have to specify what the real distribution is that you want.

1) clamp - see Xavier's response. This will give you more values at exactly 100 and/or exactly 0 than normalvariate would specify, 2) discard - this will throw away any values outside the range, and try again. And in this case, a loop is essential, plus some mechanism to handle the case where the loop would never terminate. For example, suppose x is 10000.



--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to