(sorry Vincent, I sent it to you but not the mailing list.)<br><br><div class="gmail_quote">Good luck, here are my answers:<br><br>Why not have clamp in the class? Because Clamp itself is a reusable function. I was rather surprised it's not in the standard math module.<br>
<br>if __name__ == "__main__" is only meaningful when the .py file itself is run as the main file (like typing in python name.py that has this code in the console). Otherwise if this file was imported and run in any other python run-time, including the standard console, the "__main__" part won't execute at all. The only purpose of that was to print out 10 random samples.<br>

<br>If you're not sure if this is what you want, then um.. not much I can do there. What is this class originally for?<br><br>If you feel the clamp is too huge, well, I'm always interested in improvements/alternatives!<div class="im">
<br>
<br>Best regards,<br><br clear="all">Ching-Yun "Xavier" Ho, Technical Artist<br><br>Contact Information<br>Mobile: (+61) 04 3335 4748<br>Skype ID: SpaXe85<br>Email: <a href="mailto:contact@xavierho.com" target="_blank">contact@xavierho.com</a><br>

Website: <a href="http://xavierho.com/" target="_blank">http://xavierho.com/</a><br>
<br><br></div><div><div></div><div class="h5"><div class="gmail_quote">On Sat, Jun 20, 2009 at 10:54 PM, Vincent Davis <span dir="ltr"><<a href="mailto:vincent@vincentdavis.net" target="_blank">vincent@vincentdavis.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>> # Clamp a normal distribution outcome<br>
><br>
> import random<br>
><br>
> class applicant():<br>
>     def __init__(self, x, y):<br>
>         self.randomnum = clamp(random.normalvariate(x, y), 0, 100)<br>
><br>
> def clamp(input, min=0, max=100):<br>
>     """Clamps the input between min and max.<br>
><br>
>     if  input < min, returns min<br>
>         min < input < max, returns input<br>
>         input > max, returns max<br>
><br>
>     Default: min = 0, max = 100."""<br>
>     if input < min:<br>
>         return min<br>
>     elif input > max:<br>
>         return max<br>
>     else:<br>
>         return input<br>
><br>
> if __name__ == "__main__":<br>
>     for num in range(10):<br>
>         print applicant(random.randint(0,100),<br>
> random.randint(0,100)).randomnum<br>
<br>
</div>Why not have the def clamp inside the class? I would prefer to keep<br>
everything I need for the class together.<br>
I am new to classes but I have to say things like if __name__ ==<br>
"__main__": have no intuitive meaning to me. It is true I don't know<br>
what __name__ and __main__ do and I can look it up but I don't even<br>
have a guess based on the names and usage.<br>
<br>
I am Now not sure if that is what I want or If I want to redraw from<br>
the distribution. I am wanting to simulate test scores. My option see<br>
to be to draw from a normal (I don't want linear) distribution and<br>
scale it to 0-100 or clamp it as you (Xavier) suggested or draw from<br>
the distribution again (this is what I was thinking) I think this is<br>
still what I want but I should look up the implications of each. The<br>
problem I have with the clamp is that the tails in the sample could be<br>
large.<br>
<br>
Thanks<br>
Vincent<br>
<font color="#888888">--<br>
</font><div><div></div><div><a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</div></div></blockquote></div><br>
</div></div></div><br>