samedi 20 janvier 2018

How to randomly pick an index of a given value in a array?

Assume I have the following 2D array:

[[0, 1, 0, 1, 0, 1, 0, 1],
[1, 0, 1, 0, 1, 0, 1, 0],
[0, 1, 0, 1, 0, 1, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[-1, 0, -1, 0, -1, 0, -1, 0],
[0, -1, 0, -1, 0, -1, 0, -1],
[-1, 0, -1, 0, -1, 0, -1, 0]]

How do I get a random index for the value "1" for example ?




Aucun commentaire:

Enregistrer un commentaire