www.pudn.com > goodchessGame.zip > GenerationRandomNumbers.cpp


#include "StdAfx.h" 
#include "GenerationRandomNumbers.h" 
 
int *ArrayTotalCards = NULL; 
 
int * ArrayTotalCardsFill(int nNumOfDecks)		//function that generates unique random number and fills the array ArrayTotalCards 
{ 
	srand( (unsigned)time( NULL ) ); 
	int Total = 52*nNumOfDecks; 
	ArrayTotalCards = new int[Total]; 
 
	for(int i = 0; i < Total; ++i) 
	{ 
		ArrayTotalCards[i] = i+1; 
	} 
 
	for(int j = 0; j < Total; ++j) 
	{ 
		int arrIndex = rand()%Total; 
		--Total; 
 
		int temp = ArrayTotalCards[Total]; 
		ArrayTotalCards[Total] = ArrayTotalCards[arrIndex]; 
		ArrayTotalCards[arrIndex] = temp; 
	} 
 
	for (int i=0; i<=((52 * nNumOfDecks)-1); i++) 
	{ 
		int y = ArrayTotalCards[i]; 
		int icard = y % 52; 
		if (icard == 0) 
		{ 
			icard=52; 
		} 
 
		ArrayTotalCards[i] = icard; 
	} 
 
	int counter = 0; 
	for(int i = 0; i< 52*nNumOfDecks; ++i) 
	{ 
		if(ArrayTotalCards[i] == 52) 
			++counter; 
	} 
 
 
	return &ArrayTotalCards[0]; 
} 
 
void CleanUp() 
{ 
	delete [] ArrayTotalCards; 
	ArrayTotalCards = NULL; 
} 
 
int CreateJoker()		//creates the number used as the bitmap index for the joker 
{ 
	srand( (unsigned)time( NULL ) ); 
	 
	int x = rand() % 52; 
	if (x == 0) 
		x = 52; 
	return x; 
}