How to put random numbers into a list?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eastband
    New Member
    • Jul 2006
    • 2

    How to put random numbers into a list?

    This is for homework...
    I need to generate a list of random numbers on command

    =============== =============== =============== =============
    ? random 5
    Result: [0.0079262051586 875826, 0.9649961654385 576, 0.2975428466312 4386, 0.5733452023003 2837, 0.7884889111200 0485]
    =============== =============== =============== =============

    above is the example given on the assignment
    if the user type "random 5"
    the result should be like the next line

    I did find the way to generate multiple random numbers(as below)
    however I was unable to put it into one list
    =============== =======
    for i in range(5):
    [random.random()]


    0.8267187827840 5198
    0.0678164606707 88947
    0.2046557082611 6297
    0.4542275178292 7828
    0.8847390502891 7987
    =============== =======

    Please and Thank You for replying
  • dvs
    New Member
    • Jul 2006
    • 12

    #2
    Code:
    from random import random
        
    print "Result:", [random() for r in range(5)]

    Comment

    • eastband
      New Member
      • Jul 2006
      • 2

      #3
      Thanks for the reply

      Comment

      Working...