BOOL makeRands(const int nCount, const DWORD* pInArray, DWORD* pOutArray)
{
if ( 0>=nCount || NULL==pInArray || NULL==pOutArray )
{
return FALSE;
}
// pOutArray[i] 表示 pInArray[i] 的位序
srand( (unsigned)time( NULL ) );
for (int i=0; i<nCount; i++)
{
int RANGE_MIN = 0;
int RANGE_MAX = nCount;
if (i==0) pOutArray[i] = rand()%(RANGE_MAX-RANGE_MIN) + RANGE_MIN;
else
{
while(1)
{
int flag=0;
int value = rand() % ( RANGE_MAX - RANGE_MIN ) + RANGE_MIN;
for(int j=0; j<i; j++)
{
if( pOutArray[j] == value )
{
flag = 1;
break;
}
}
if ( flag != 1 )
{
pOutArray[i] = value;
break;
}
}
}
}
// pOutArray[i] 表示 pInArray[i] 的位序
for (int i=0; i<nCount; i++)
{
int m = pOutArray[i];
pOutArray[i] = pInArray[m];
}
return TRUE;
}
{
if ( 0>=nCount || NULL==pInArray || NULL==pOutArray )
{
return FALSE;
}
// pOutArray[i] 表示 pInArray[i] 的位序
srand( (unsigned)time( NULL ) );
for (int i=0; i<nCount; i++)
{
int RANGE_MIN = 0;
int RANGE_MAX = nCount;
if (i==0) pOutArray[i] = rand()%(RANGE_MAX-RANGE_MIN) + RANGE_MIN;
else
{
while(1)
{
int flag=0;
int value = rand() % ( RANGE_MAX - RANGE_MIN ) + RANGE_MIN;
for(int j=0; j<i; j++)
{
if( pOutArray[j] == value )
{
flag = 1;
break;
}
}
if ( flag != 1 )
{
pOutArray[i] = value;
break;
}
}
}
}
// pOutArray[i] 表示 pInArray[i] 的位序
for (int i=0; i<nCount; i++)
{
int m = pOutArray[i];
pOutArray[i] = pInArray[m];
}
return TRUE;
}