By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,536 Members | 1,290 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,536 IT Pros & Developers. It's quick & easy.

How to put random numbers into a list?

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

================================================== ========
? random 5
Result: [0.0079262051586875826, 0.9649961654385576, 0.29754284663124386, 0.57334520230032837, 0.78848891112000485]
================================================== ========

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):


Please and Thank You for replying
Jul 19 '06 #1
Share this Question
Share on Google+
2 Replies

P: 12
Expand|Select|Wrap|Line Numbers
  1. from random import random
  3. print "Result:", [random() for r in range(5)]
Jul 20 '06 #2

P: 2
Thanks for the reply
Jul 23 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.