-3

For example, there is an array like this ==> array[10][10]

I want to pick a random element of this array like array[5][7] and assign it to 0.

How can I do it?

Anatoly
23.2k3 gold badges33 silver badges46 bronze badges
asked Dec 15, 2020 at 16:17
2
  • if its random array[5][7] = 0; thats it. Commented Dec 15, 2020 at 16:40
  • Does this answer your question? Weighted random selection from array Commented Dec 15, 2020 at 22:22

1 Answer 1

1

Should be something like:

srand((unsigned) time()); // For different result every second
int x = rand() % 10;
int y = rand() % 10;
array[x][y] = 0;
answered Dec 15, 2020 at 16:48
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.