I cannot copy random numbers without repeating in a map.
Unhandled exception at 0x0040115e in file.exe: 0xC0000005: Access violation writing location 0xabababaf.
int **map;
int randomize(int numberToSelect,int range,int counter){
int* remainingNumbers = new int[range];
int* chosenNumbers = new int[numberToSelect];
for(int i = 0; i < range; i++)
remainingNumbers[i] = i;
for(int i = 0; i < numberToSelect; i++)
{
const int selectedElement = rand() % (range - i);
chosenNumbers[i]=remainingNumbers[selectedElement] + 1;
remainingNumbers[selectedElement]=remainingNumbers[range-i];
}
delete [] remainingNumbers;
for(int i = 0; i < counter; i++)return chosenNumbers[i];
delete [] chosenNumbers;
}
bool Memalloc(int Width,int Height)
{
map = new int*[Width];
for( int x=0;x<Width;x++){
map[x] = new int[Height];
}
return true;
}
void create(int Width, int Height){
Memalloc(Width,Height);
int Area,x,y,balance;
Area = Width * Height;
x = 1, y = 0,balance = 0;
for(int i = 0; i < Area; i++){
if(y < i - balance)y++;
if(y ==Height)x+=1,balance = y,y=1;
map[x][y] = randomize(Area, Area,i);
}
delete [] map;
}