By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,587 Members | 1,070 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,587 IT Pros & Developers. It's quick & easy.

Assigning the number one to a random position of a 10x10 array

P: 1
I've created the array and I'm trying to work out how to assign the number one to a random position. The goal is to create a 'treasure hunt'.
Apr 26 '17 #1
Share this Question
Share on Google+
1 Reply


Frinavale
Expert Mod 5K+
P: 9,731
Generate a random number between 0 and 9 for an index within an array (the X-position). Then generate another random between 0 and 9 for the index of the array to put the item in (the Y-position).

Once you have a random X and a random Y position, check to see if there is an item at that position. If there is, then generate new X and Y numbers until you find a position that is not taken.
May 2 '17 #2

Post your reply

Sign in to post your reply or Sign up for a free account.