Hello. I'm running a game online and designing a program to help me generate Enemy Stats. Basically, it's supposed to generate 25 numbers between 0 and 7(to represent 8 Attributes on a 25 Point Buy system) and count how many times each number shows up.
Here's what the code looks like:
Code:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int Generate()
{
int r= rand();
int s= r%7;
cout<<r<<"\t"<<s<<endl;
return s;
}
int main()
{
int Stats[8];
for(int i=0; i<=8; i++)
{
Stats[i]=0;
}
for (int i=0; i<25; i++)
{
srand(time(NULL));
int x= Generate();
Stats[x]++;
}
for(int i=0; i<=8; i++)
{
cout<<"Stats["<<i<<"]= "<<Stats[i]<<endl;
}
}
And here's two outputs.
1:
Code:
1213308922 0 1213308922 0 1213308922 0 1213308922 0 1213308922 0 1213308922 0 1213308922 0 1213308922 0 1213308922 0 1213308922 0 1213308922 0 1213308922 0 1213308922 0 1213308922 0 1213308922 0 1213308922 0 1213308922 0 1213308922 0 1213308922 0 1213308922 0 1213308922 0 1213308922 0 1213308922 0 1213308922 0 1213308922 0 Stats[0]= 25 Stats[1]= 0 Stats[2]= 0 Stats[3]= 0 Stats[4]= 0 Stats[5]= 0 Stats[6]= 0 Stats[7]= 0 Stats[8]= 0 Disallowed system call: SYS_socketcall
2:
Code:
1478770843 4 1478770843 4 1478770843 4 1478770843 4 1478770843 4 1478770843 4 1478770843 4 1478770843 4 1478770843 4 1478770843 4 1478770843 4 1478770843 4 1478770843 4 1478770843 4 1478770843 4 1478770843 4 1478770843 4 1478770843 4 1478770843 4 1478770843 4 1478770843 4 1478770843 4 1478770843 4 1478770843 4 1478770843 4 Stats[0]= 0 Stats[1]= 0 Stats[2]= 0 Stats[3]= 0 Stats[4]= 25 Stats[5]= 0 Stats[6]= 0 Stats[7]= 0 Stats[8]= 0 Disallowed system call: SYS_socketcall
Note that the number does change, but only between runs. What am I doing wrong?