Re: Generate a sequence of random numbers that sum up to 1?
- From: "fumanchu" <fumanchu@xxxxxxxx>
- Date: 23 Apr 2006 13:54:48 -0700
I'm surprised noone has pursued a course of subtraction rather than
division. Say you want 10 numbers:
.... value = random.random() * ss = 1.0
n = []
for x in xrange(9):
.... n.append(value)
.... s -= value
....
[0.7279111122901516, 0.082128708606867745, 0.0080516733577621798,n.append(s)
n
0.12122060245902817, 0.0034460458833209676, 0.0021046234724371184,
0.054109424914363845, 0.00035750970249204185, 0.00051175075536832372,
0.00015854855820800087]
1.0sum(n)
Either:
1) Just because they're *ordered* doesn't mean they're not *random*,
or
2) You all now know why I'm not a mathematician. ;)
It seems to me that the only constraint on the randomness of my results
is the OP's constraint: that they sum to 1. I'd be fascinated to learn
if and why that wouldn't work.
Robert Brewer
System Architect
Amor Ministries
fumanchu@xxxxxxxx
.
- Follow-Ups:
- Re: Generate a sequence of random numbers that sum up to 1?
- From: Terry Reedy
- Re: Generate a sequence of random numbers that sum up to 1?
- From: Alex Martelli
- Re: Generate a sequence of random numbers that sum up to 1?
- References:
- Generate a sequence of random numbers that sum up to 1?
- From: Anthony Liu
- Generate a sequence of random numbers that sum up to 1?
- Prev by Date: Re: bug in modulus?
- Next by Date: Re: Problem calling math.cos()
- Previous by thread: Re: Generate a sequence of random numbers that sum up to 1?
- Next by thread: Re: Generate a sequence of random numbers that sum up to 1?
- Index(es):