Sep 10, 2013 at 5:25pm UTC
How to store 0 to 25 number randomly in 5x5 array.Can u teach me how to do it
Last edited on Sep 10, 2013 at 5:48pm UTC
Sep 10, 2013 at 5:30pm UTC
How to get random numbers between 0 - 25 and store them in an array:
1 2 3 4
int myArray[10];
for (int i = 0; i < 10; ++i)
myArray = rand() % 26;
How to get the numbers 0-25 shuffled randomly:
1 2 3 4 5 6
int myArray[26];
for (int i = 0; i < 26; ++i)
myArray[i] = i;
std::random_shuffle( myArray, myArray + 26 );
rand() comes from <cstdlib>
std::random_shuffle() comes from <algorithm>
Last edited on Sep 10, 2013 at 5:49pm UTC
Sep 10, 2013 at 5:51pm UTC
How to get it for 5x5 array...
Sep 10, 2013 at 5:58pm UTC
well you could just copy it over...
1 2 3 4
int fiveByfive[25][25];
for (int i = 0; i <5; ++i)
for (int j = 0; j < 5; ++j)
fiveByfive[i][j] = myArray[i * 5 + j ];
standard utilities are not really meant for multi-dimensional arrays because they are not the most efficient means of doing... anything.
Last edited on Sep 10, 2013 at 6:00pm UTC
Sep 10, 2013 at 6:36pm UTC
nvm. OP has abandoned the thread.
Last edited on Sep 15, 2013 at 5:22pm UTC
Sep 10, 2013 at 6:51pm UTC
I advice against that as it's hackish. ;-P
Sep 12, 2013 at 5:00am UTC
@Josue. Care to suggest a better method?
What do you find to be 'hackish' about it? Just curious.
Last edited on Sep 12, 2013 at 5:42am UTC