Random number between 7 to 10

Hello,
I have a small problem. I'm trying to generate random number from 7 to 10 but all i got is "Error C2661: 'rand' : no overloaded function takes 1 argument"

there is my code:

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
26
27
28
29
30
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <time.h>

using namespace std;

void init_Function(); // init function

// Global variables
int variable;

int _tmain(int argc, _TCHAR* argv[])
{
	init_Function();
	system("PAUSE");
	return 0;
}

void init_Function()
{
	int min = 7;
	int max = 10;

	srand((unsigned)time(NULL));
	// creating variable
	variable = rand(max - min);
	cout << variable << endl;

}
1) Do never, ever, use precompiled headers.
2) try return (unsigned)min+int(((max - min) +1)*rand()/(RAND_MAX + 1.0));
Thank you for your help, it worked great :)
@ Paul, what the hell does that have to do with the OP's question?

@ OP:
http://www.cplusplus.com/reference/cstdlib/rand/

shows how to generate random numbers in a desired range.
What's so bad about precompiled headers
Topic archived. No new replies allowed.