mardi 11 août 2015

how to print lists of random numbers in python

I'm trying to generate and print some lists of random numbers(0 to 1) of length 1,4 and 9. For example:

[0.2341434134]  
[0.1314124124,0.341241234213,0.1234123412,0.12341243]  
[0.412341,0.141234,0.1412341,0.141234,0.1412341,0.1241234,0.1231243,0.134123,0.1234123]

This is what I've got but output is very different.

import random  
the_list = []

    def generateLists(j): 
        while (len(the_list) < i^2):  
            randNum = random.random()  
            the_list.append(randNum)  

        return the_list

    for i in range(1,4):  
        print(generateLists(i))  
        del the_list[:]




Aucun commentaire:

Enregistrer un commentaire