Random number function
I want to make a function that returns a random number but everytime i call the function it returns the value same as when i first called it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int Random()
{
srand((int)time(0));
return (rand()%10)+1;
}
int main()
{
for ( int i = 0 ; i < 10 ; i++ )
{
cout << Random() << endl;
}
return 0;
}
|
Sorry for my english.
move the srand((int)time(0));
call into main before your for loop.
Thank you , its now working how it should :)
Topic archived. No new replies allowed.