c++ generator

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "stdafx.h"
#include "iostream"
#include "string"
using namespace std;
int main ()
{ 
	int a;
	do
	{
		cout <<" press any key to obtain a random card, -1 to stop " ;
		cin >> a ;
		int cardvalue = rand () % 13 + 1 ;
		int cardsuit = rand () % 4 +1 ;
		cout <<" cardvalue " << cardvalue << " cardsuit "<< cardsuit <<endl;
	}
	while ( a!= -1 );
	return 0;
}

but every time i run my program, i get the same combination... how can i make my program completely random ?
You need to seed your random number generator: http://en.cppreference.com/w/cpp/numeric/random/srand
Topic archived. No new replies allowed.