|
-
September 30th, 2003, 05:08 PM
#1
2D Array & random numbers
I've got a two dimensional array which needs the first and third rows to match. In a "for" loop, I'm creating a random number (0-9)and assigning it to the first element in the array, and then incrementing the column element and repeating the process, giving me four random numbers in row1 (element[0]). Here's what I'm working with:
Code:
int i;
int Game[3][4] = {0};
for (i=0; i<=3; i++)
{
Game[0][i] = rand() % 10;
Game[2][i] = Game[0][i];
}
Is there a way to set one row equal to another without looping through the two as I have here? Also, each time I run this piece of code I get the same "random" numbers. I tried using randomize() and random() but couldn't make it work. I kept getting erros that randomize and random were not declared variables. How can I ensure the numbers I'm getting differ each time?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|