Shuffling Array Help!

I am having a lot of trouble regarding trying to shuffle arrays. I have a data file that the user interactively chooses. The file contains to sets of data. The first item is a 5 digit number and the second item is a character ('C', 'D', 'E', or 'R'). For example, the file looks like this (except it contains 15 lines):
1012 C
22 R
33251 D
89 E

I have created two parallel arrays:
1
2
3
4
5
const int arraySize = 15;
// array for first item
int songId[arraySize];
// array for second item
char typeOfSong[arraySize];


I have to randomize these parallel arrays but I am NOT allowed to use random_shuffle or anything in the STL. I am also not allowed to have any of the elements repeat. I have been trying a multitude of things but can not seem to come up with any code that works at all. Can anyone provide some insight?
1) use structures instead of two parallel arrays.
2) Look at random_shuffle() implementation and get the idea behind it here
http://en.cppreference.com/w/cpp/algorithm/random_shuffle
(Basically take each element and swap it with random element)
Technically, std::rand() isn't part of the STL because it's not a function template: it's part of the C library of C++.

Are you permitted to use it?
Actually you would not need to use the shuffle tool if you use a loop function
( i.e. while or for) and a series of if and if else statements you can make your program check to see if the random number generated by your random number generator array has already been produced. You need to write somewhere in your program what happens if the array has already been chosen so it does not happen again.

Here is a hint to get you started

your random array should initially look this:

RandomSongArray[a] = rand ()% NUM

where a is some non constant integer defined by your for loop or somewhere in your while loop and NUM is the
size of your array (in this instance 15)


Topic archived. No new replies allowed.