calculating a self.value, self.randomnum = normalvariate(x, y)
contact at xavierho.com
Sat Jun 20 09:01:58 EDT 2009
(sorry Vincent, I sent it to you but not the mailing list.)
Good luck, here are my answers:
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.
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.
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?
If you feel the clamp is too huge, well, I'm always interested in
Ching-Yun "Xavier" Ho, Technical Artist
Mobile: (+61) 04 3335 4748
Skype ID: SpaXe85
Email: contact at xavierho.com
On Sat, Jun 20, 2009 at 10:54 PM, Vincent Davis <vincent at vincentdavis.net>wrote:
> > # Clamp a normal distribution outcome
> > import random
> > class applicant():
> > def __init__(self, x, y):
> > self.randomnum = clamp(random.normalvariate(x, y), 0, 100)
> > def clamp(input, min=0, max=100):
> > """Clamps the input between min and max.
> > if input < min, returns min
> > min < input < max, returns input
> > input > max, returns max
> > Default: min = 0, max = 100."""
> > if input < min:
> > return min
> > elif input > max:
> > return max
> > else:
> > return input
> > if __name__ == "__main__":
> > for num in range(10):
> > print applicant(random.randint(0,100),
> > random.randint(0,100)).randomnum
> Why not have the def clamp inside the class? I would prefer to keep
> everything I need for the class together.
> I am new to classes but I have to say things like if __name__ ==
> "__main__": have no intuitive meaning to me. It is true I don't know
> what __name__ and __main__ do and I can look it up but I don't even
> have a guess based on the names and usage.
> I am Now not sure if that is what I want or If I want to redraw from
> the distribution. I am wanting to simulate test scores. My option see
> to be to draw from a normal (I don't want linear) distribution and
> scale it to 0-100 or clamp it as you (Xavier) suggested or draw from
> the distribution again (this is what I was thinking) I think this is
> still what I want but I should look up the implications of each. The
> problem I have with the clamp is that the tails in the sample could be
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list