Re: number generator

2007-03-11 Thread Army1987

"cesco" <[EMAIL PROTECTED]> ha scritto nel messaggio 
news:[EMAIL PROTECTED]
>I have to generate a list of N random numbers (integer) whose sum is
> equal to M. If, for example, I have to generate 5 random numbers whose
> sum is 50 a possible solution could be [3, 11, 7, 22, 7]. Is there a
> simple pattern or function in Python to accomplish that?
>
> Thanks and regards
> Francesco


You can initialize a list to [1, 1, 1, 1, 1], and generate 45 random 
integers between 1 and 5, and every time a number is generated, increase the 
Nth number in the list by one.

Not all distinct lists will have the same chance of occurring, e.g. [46, 1, 
1, 1, 1] will be much less likely than [10, 10, 10, 10, 10]. Depending on 
what you need these numbers for, it can be a good thing or a bad thing.

--Army1987


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


Re: Python Feature Request: Explicit variable declarations

2007-04-14 Thread Army1987
"jamadagni" <[EMAIL PROTECTED]> ha scritto nel messaggio 
news:[EMAIL PROTECTED]
>> Languages like Perl and VB need a strict mode because they will
>> auto-vivify variable for you.  I.e. they will bring variables to life
>> with defined or undefined values if you use them in a l-value (left hand
>> side of an assignment) without having declared them prior.  If you do
>> that in Python you get an exception.
>
> I don't comprehend. I can just type a = 5 in a new Python session and
> I get no exception. Python currently does not require variables to be
> declared before they are used on the LHS.

I think (s)he meant right hand. 


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


Re: Getting started with python

2007-04-15 Thread Army1987
"Paddy" <[EMAIL PROTECTED]> ha scritto nel messaggio 
news:[EMAIL PROTECTED]

> On a different tack, from:
> http://tickletux.wordpress.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/
> It seems you need to learn how to write a Fizz-Buzz
> program to get a job now-a-days :-)

Something less idiotic? I took longer to type a program to do that than to 
figure out how to do that. 


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