This code should roughly follow the format you need, I provide both a C++11 solution using the random header and uniform_int_distribution with live example which should be preferred if possible::
#include <iostream>
#include <random>
#include <cstdlib>
int main()
{
std::random_device rd;
std::mt19937 e2(rd());
int V = 10 ;
std::uniform_int_distribution<int> dist1(0, V);
for (int i = 0; i < V; ++i)
{
for (int k = i+1; k < V; ++k)
{
int index1 = dist1(e2) ;
int index2 = dist1(e2) ;
std::cout << "( " << index1 << " , " << index2 << ") " ;
}
std::cout << std::endl ;
}
std::cout << std::endl ;
}
I also provide code using rand
as well whose formula is based on the How can I get random integers in a certain range? entry from the C FAQ live example:
#include <iostream>
#include <cstdlib>
int main()
{
int V = 10 ;
for (int i = 0; i < V; ++i)
{
for (int k = i+1; k < V; ++k)
{
int index1 = rand() / (RAND_MAX / V + 1) + 1 ;
int index2 = rand() / (RAND_MAX / V + 1) + 1;
std::cout << "( " << index1 << " , " << index2 << ") " ;
}
std::cout << std::endl ;
}
std::cout << std::endl ;
}