help with 4 random number

i need to have 1-8 make random on the cp1,cp2,cp3,cp4, but it cant be the same numbers and it needs to be different ever time.
its for c++ and netbeans
1
2
3
4
5
//so like this
    cp1=5;
    cp2=2;
    cp3=1;
    cp4=7;
Last edited on
You can use a simple LNG, you will need to set a seed for the generator:

1
2
3
4
5
6
#include <ctime>
#include <random>

std::srand(std::time(nullptr));
int cp1 = std::rand() % 8 + 1;
// ... 


Or you could use a more advanced, non-global engine like:
1
2
3
4
std::mt19937 en(std::time(nullptr));
std::uniform_int_distribution<int> dist(1, 8);
int cp1 = dist(en);
// ... 
Topic archived. No new replies allowed.