Random number

Im looking for a way to get a random number, I tried the code below but it doesnt give me a random number each time i cout it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;

int main(){
int r;
while(true){
	srand(time(0));
	r = rand() % 10 + 1;
	cout << r <<endl;
	}
return 0;
}
Your program will make a new random number each time the time changes.

isnt there a faster way so I dont have to wait for the time to change ?
don't put srand in the loop.
ohh thank you
Topic archived. No new replies allowed.