Hi, I'm trying to take the value of elements in one array and scramble
them up so that a new array contains a random version of the first with
out duplicates. I thought the following code would do but I'm not
geeting the second array filled with the first ones elements.
#include <iostream.h>
#include <time.h>
void main()
{
int i = 0, j = 0;
int intSeq[7] = {1,2,3,4,5,6,7};
int intRand[7] = {0,0,0,0,0,0,0};
for (i = 0; i <= 6; i++)
{
while(intRand[j] == 0)
{
srand(time(NULL));
j = random(7);
intRand[j] = intSeq[i];
}
}
/*From here on is code for output to display*/
cout << "intSeq[] = ";
for (i = 0; i <= 6; i++)
{
cout << intSeq[i] << " ";
}
cout << endl;
cout << "intRand[] = ";
for (i = 0; i <= 6; i++)
{
cout << intRand[i] << " ";
}
cout << endl << endl;
system("pause");//Function for closing salutation.
}
The output I get from my code shows assignment of one element only, does
anyone know where I'm going wrong or have an easy scramble algotithm?
Many thanks for reading, Will.


|