mercredi 26 septembre 2018

Writing a function inside a class to generate a list of SIX random numbers between a given range

I want to generate a list of random numbers where the range and the length of the list can be varied later without modifying the function.So i thought of creating a function and the code i tried using python 3x is as follows:

class Traffic_matrix:

  def All_traffic(self,first,last,length):
      all_t=[]
      for i in range(length):
        all_t.append (random.randint(first, last))
all_t = Traffic_matrix()
print(all_t.All_traffic(23,56,6))

I know i have made a mistake somewhere and dont know what it is. Please help me out to sort this.




Aucun commentaire:

Enregistrer un commentaire