Generate a sequence of random numbers that sum up to 1?
Mel Wilson
mwilson-to at sympatico.ca
Fri Apr 21 22:52:20 EDT 2006
Anthony Liu wrote:
> I am at my wit's end.
>
> I want to generate a certain number of random numbers.
> This is easy, I can repeatedly do uniform(0, 1) for
> example.
>
> But, I want the random numbers just generated sum up
> to 1 .
>
> I am not sure how to do this. Any idea? Thanks.
numbers.append (random.uniform (0, 1.0-sum(numbers)))
might help, perhaps.
or
scaled = [x/sum(numbers) for x in numbers]
Mel.
>
More information about the Python-list
mailing list