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.
uservalue is greater thanlen(range(w))(orlen(range(h)))random.sampletwice independently doesn't make a lot of sense to me. That means that all of the points you choose from the grid will have completely unique x coordinates and y coordinates - for example, you'll never end up with both (0,0) and (0,1). If you want actually random coords, you need to create a single list of all coordinates and callsampleon that list just once.