jeudi 17 décembre 2015

Python randomnumber array

So, i have a small issue witch creating random numbers for an 2d array in python.

I have a matrix looking like this

matrix:
       row = ['.' for i in range(w)]
        self.matrix = [row]
        for j in range(h - 1):
            row = ['.' for i in range(w)]
            self.matrix.append(row)

w = int(input("please insert the width of the array: "))
h = int(input("please insert the height of the array: "))

user = int(input("please insert a number for objects: "))

x = random.sample(range(w), user)
y = random.sample(range(h), user)

list(zip(x, y))

So, now i want to create so many random numbers as user input. For example, it the user inputs 100, i need 100 numbers from x and y, so that i can use them as position, to insert objects randomly into the array.

But if the width and height are smaller then userinput i get an error.




Aucun commentaire:

Enregistrer un commentaire