how can i random this program?

hi.. can you give me some guide how can i random this program.. tnx..!
heres my code..



#include<cstdlib>
#include<iostream>
#include<time.h>

using namespace std;
int x,stud;
int group [50];

int main()
{

int srand , count=0;

for (x=0; x<50; x++)
group[x]=0;

cout<<"Input the number of the students: ";
cin>>stud;

srand = rand() % stud + 1;
//cout<<srand<<end
if(group [srand]==0)



cout<<"Enter the group of the students: ";
srand = rand() % stud + 1;




return 0;
}
What is the purpose of your program?

Here is an example of pseudo random number generation:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<iostream>
#include<cstdlib>
#include<ctime> 

using namespace std;

int main()
{
    int randomNumber;

    srand(time(NULL)); 

    for (int i = 0; i < 50; i++)
    {
        randomNumber = rand() % 100 + 1;
        cout << randomNumber << '\n';
    }
} 



This will output 50 random numbers between 0 and 100.
time.h is from c, to use it in c++ you can include it the way you did but the preferred way is using it's new name ctime. Check out this link about srand( ): http://www.cplusplus.com/reference/clibrary/cstdlib/srand/
Topic archived. No new replies allowed.