473,396 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
1 1406
Frinavale
9,735 Expert Mod 8TB
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

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

Similar topics

2
by: mortb | last post by:
Why is line number and position = 0 in the code below? Valiation errors are found but not their position. cheers, mortb public static void Main() { XmlDocument xml = new XmlDocument();...
0
by: thangs1 | last post by:
C# Code: for(int a =0;a< (some array);a++) { } variable a is assigned a random value. Then i deleted that variable and again typed. Now it assigns correctly.Whats the reason for this in...
3
by: James Fang | last post by:
Hi all, I need to edit a random position of a file, for e.g, the 500th byte. To keep portability, I would like to use standard C++ instead of os apis. Could you help on this? Thanks
10
by: cherryst152 | last post by:
I'm trying to make an array from a query and then randomly select 10 values from the array, but the error i keep getting is that it's not reading as an array. Thanks in advance for anyone who can...
1
by: boomba | last post by:
hi i have a 2 dimensional array where im trying to create an object (territory) in an if statement when the array is searched and when a certain number is found eg a territory is created and...
3
by: Chris Saunders | last post by:
My C skills are rather meager so forgive me if I do not express my question clearly enough. Here is a struct that is declared in Windows: typedef struct _REPARSE_GUID_DATA_BUFFER { DWORD...
3
by: thesinnerishere | last post by:
this is regarding the last number standing problem. it requires the number in an array to be extracted at a specified position . then the array needs to traverse through the right position of the...
2
by: xtranice | last post by:
I icreated a two-dimensional array in which i placed two stack of cards. One is numerical and one is random. Then i created two sets of strings which i tried to assign to the cards so I could print...
7
by: abhinuke | last post by:
Been brushing up my C,C++ for my new venture in Graduate Studies for this fall.I am doing basic programs in which I am trying this one right now. A 5-digit positive integer is entered through the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.