Write a program that generates a list of 100 random integers

Write a program that generates a list of 100 random integers in [0, 100), which means between 0 and 99 inclusive.

To solve this problem, use the randomInteger function you developed for the A3 Functionsassignment. In other words, use a loop to call the randomInteger function 100 times.

Save the program output by redirecting the standard output stream to a file. To do this, run the program as follows.

Open numbers.txt in a text editor to see the result.

Solution

#include <iostream>
#include <stdlib.h> /* we use this header file for srand, rand function */
#include <time.h> /* we use this header file for time */
#include <fstream> //Stream class to write on files

using namespace std;
int randomInteger(); /*randomInteger function declaration for random number generation*/

int main()
{
srand (time(NULL));

/*ofstream data type is used to create files and to write information to files*/
ofstream file(\"numbers.txt\");

/* for loop call randomInteger function 100 times*/
for(int i=0;i<100;i++)
{
/* output storing in file numbers.txt by calling randomInteger function */
file<<\"Random Number \" << i+1 <<\" is : \"<<randomInteger()<<endl;

}

return 0;
} //End of main

/*randomInteger function definition */
int randomInteger()
{
/* random number generation between 0 to 99*/
int rand_num=((rand() % 100));
return rand_num;

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/* after execution this program open number.txt file in same directory to see output*/

I wrote this program in C++ prgramming language . if you need in different language like C and Java, then comment me. i will send in different lanaguage.

if you are not able to open numbesr.txt then comment me i will show you steps.

If you have any query, please feel free to ask

Thanks a lot

Write a program that generates a list of 100 random integers in [0, 100), which means between 0 and 99 inclusive. To solve this problem, use the randomInteger f

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site