Populating an array with unique random integers

I am trying to populate an array with random but unique integers for later use in a minesweeper game. I am not very familiar with rand and srand.

Here's an example from what I have been trying:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
using namespace std;

#include <iostream>
#include <time.h>
#define noofmines 5

int randarray[noofmines];
char grid[5][5];

int mineposition()

{
	int n;
	srand(time(NULL));
	for (n=0; n<noofmines; n++)
	{
		
	randarray[n]= rand() % noofmines+1;
	cout<<randarray[n];
	getchar();
	
	}
	return 0;

}


This populates randarray with 5 random integers ranging from 1 - 5. However they are not UNIQUE. How can I fix this?
Last edited on
Topic archived. No new replies allowed.