Re: Generate a sequence of random numbers that sum up to 1?

Discussion in 'Python' started by Anthony Liu, Apr 22, 2006.

  1. Anthony Liu

    Anthony Liu Guest

    Thanks a lot, Alex and Gerard.

    I am actually not very concerned about the
    inter-dependency of the floating numbers generated
    randomly. They are good enough if they are subject to
    the constraint of summing up to 1.

    It is simply not worth the time to get an HMM by
    training it on a large corpus. My sole purpose is to
    test the predicting power of an HMM, given a set of
    parameter values.

    I will definitely try out your snippet and see if it
    works. Thanks a lot!

    --- Alex Martelli <> wrote:

    > Anthony Liu <> wrote:
    > ...
    > > As a matter of fact, given that we have to specify

    > the
    > > number of states for an HMM, I would like to

    > create a
    > > specified number of random floating numbers whose

    > sum
    > > is 1.0.

    >
    > def forAL(N):
    > N_randoms = [random.random() for x in
    > xrange(N)]
    > total = sum(N_randoms)
    > return [x/total for x in N_randoms]
    >
    >
    > Does this do what you want? Of course, the
    > resulting numbers are not
    > independent, but then the constraints you pose would
    > contradict that.
    >
    >
    > Alex
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >



    __________________________________________________
    Do You Yahoo!?
    Tired of spam? Yahoo! Mail has the best spam protection around
    http://mail.yahoo.com
    Anthony Liu, Apr 22, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shivermetimbers15
    Replies:
    12
    Views:
    413
    Amy G
    Feb 18, 2004
  2. Anthony Liu
    Replies:
    14
    Views:
    1,169
    Terry Reedy
    Apr 24, 2006
  3. Anthony Liu
    Replies:
    1
    Views:
    455
    Paul Rubin
    Apr 30, 2006
  4. Prakhar
    Replies:
    3
    Views:
    462
    Default User
    Jun 12, 2007
  5. globalrev
    Replies:
    4
    Views:
    742
    Gabriel Genellina
    Apr 20, 2008
Loading...

Share This Page