Re: number generator



"Nick Craig-Wood" <nick@xxxxxxxxxxxxxx> wrote:

Paul Rubin <http> wrote:
The fencepost method still seems to be simplest:

t = sorted(random.sample(xrange(1,50), 4))
print [(j-i) for i,j in zip([0]+t, t+[50])]

Mmm, nice.

Here is another effort which is easier to reason about the
distribution produced but not as efficient.

def real(N, M):
while 1:
t = [ random.random() for i in range(N) ]
factor = M / sum(t)
t = [ int(round(x * factor)) for x in t]
if sum(t) == M:
break
print "again"
assert len(t) == N
assert sum(t) == M
return t

It goes round the while loop on average 0.5 times.

If 0 isn't required then just test for it and go around the loop again
if found. That of course skews the distribution in difficult to
calculate ways!


I have been wondering about the following as this thread unrolled:

Is it possible to devise a test that can distinguish between sets
of:

- five random numbers that add to 50, and
- four random numbers and a fudge number that add to 50?

My stats are way too small and rusty to attempt to answer
the question, but it seems intuitively a very difficult thing.

- Hendrik

.



Relevant Pages

  • Re: number generator
    ... It goes round the while loop on average 0.5 times. ... That of course skews the distribution in difficult to ... the likelihood ratio will be 1. ...
    (comp.lang.python)
  • Re: number generator
    ... Here is another effort which is easier to reason about the ... It goes round the while loop on average 0.5 times. ... That of course skews the distribution in difficult to ...
    (comp.lang.python)
  • Re: random numbers according to user defined distribution ??
    ... Unfortunately the random module does not contain the distribution I ... arbitrary probability density function over some range, ... def integrate: ... return cdf ...
    (comp.lang.python)
  • Re: Distributing Estimated Hours over calendar working days.
    ... I have to make the cell value of that Date Column-Actiivity Row ... This gives 16 hours for the first day of distribution which is a Friday ... Third, I can start a loop to distribute the remaining 64 hours, which ...
    (microsoft.public.excel.programming)
  • Re: Does Loop Fission Work in Single Cores?
    ... distribution is meaningless on a single core. ... When it makes sense to fission a loop is hardware specific. ... you'll want to be unrolling or fusing loops than fissioning them. ...
    (comp.compilers)