whit@granite:~/public_html/cpsc146/Samples[?1034h[whit@granite Samples]$ cat rand.cpp
#include
#include
using namespace std;
const int NumChild = 10; // number of children sliding
const int MaxSlideTime = 30; // max. number of seconds/slide
int main()
{
int NewWaiting=0;
int SlideTime=MaxSlideTime;
int child=0;
srand(time(0));
SlideTime = rand()% MaxSlideTime;
cout <<"Time Child permitted to Slide: " << SlideTime << endl;
NewWaiting = (rand()%(NumChild))/ (rand()%2 + 1);
cout <<"Number of children waiting: " << NewWaiting << endl;
return 0;
}
whit@granite:~/public_html/cpsc146/Samples[whit@granite Samples]$ ./rand.o
Time Child permitted to Slide: 23
Number of children waiting: 0
whit@granite:~/public_html/cpsc146/Samples[whit@granite Samples]$ ./rand.o
Time Child permitted to Slide: 25
Number of children waiting: 4
whit@granite:~/public_html/cpsc146/Samples[whit@granite Samples]$ ./rand.o
Time Child permitted to Slide: 1
Number of children waiting: 2
whit@granite:~/public_html/cpsc146/Samples[whit@granite Samples]$ cat rand2.cpp
#include
#include
using namespace std;
const int NumChild = 10; // number of children sliding
const int MaxSlideTime = 30; // max. number of seconds/slide
int main()
{
int NewWaiting=0;
int SlideTime=MaxSlideTime;
int child=0;
// srand(time(0));
SlideTime = rand()% MaxSlideTime;
cout <<"Time Child permitted to Slide: " << SlideTime << endl;
NewWaiting = (rand()%(NumChild))/ (rand()%2 + 1);
cout <<"Number of children waiting: " << NewWaiting << endl;
return 0;
}
whit@granite:~/public_html/cpsc146/Samples[whit@granite Samples]$ ./rand2.o
Time Child permitted to Slide: 13
Number of children waiting: 3
whit@granite:~/public_html/cpsc146/Samples[whit@granite Samples]$ ./rand2.o
Time Child permitted to Slide: 13
Number of children waiting: 3
whit@granite:~/public_html/cpsc146/Samples[whit@granite Samples]$ ./rand2.0[Ko
Time Child permitted to Slide: 13
Number of children waiting: 3