Generate Random Numbers
Write a C++ Program to Generate Random Numbers between 0 and 100. Here’s simple C++ Program to Generate Random Numbers between 0 and 100 in C++ Programming Language.
Here is source code of the C++ Program to Generate Random Numbers. The C++ program is successfully compiled and run(on Codeblocks) on a Windows system. The program output is also shown in below.
SOURCE CODE : :
/* C++ Program to Generate Random Numbers between 0 and 100 */ #include<iostream> #include<stdlib.h> using namespace std; int main() { int i; //loop counter int num; //store random number cout<<"Generating Random Numbers Below :: \n\n"; for(i=1;i<=10;i++) { num=rand()%100; //get random number cout<<" "<<num<<" "; } cout<<"\n"; return 0; }
Output : :
/* C++ Program to Generate Random Number between 0 and 100 */ Generating Random Numbers Below :: 41 67 34 0 69 24 78 58 62 64 Process returned 0
Above is the source code for C++ Program to Generate Random Number between 0 and 100 which is successfully compiled and run on Windows System.The Output of the program is shown above .
If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.
Thanks for reading the post….
hi,
thanks for your great site!
I was wondering if we want to generate a random number between 0 and 100, it means [0,100], so it’s should contain also 100. if so, we should do “rand()%101”, is that right?!
yes, here it is in the interval [0; 100[
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main(){
srand(time(0));
cout<<“Random numbers generated between 1 and 100:”<<(rand()%100);
}
I am searching for program that generate random number from -100 to 100
and also show the minimum and maximum number
What is the use of
I didn’t get this, What does mean by random numbers between 0 to 100, every time i run this code the output remain same then how could we say that it’s a random number?
need to include
srand(time(0));
into your code then you’ll get a random number everytime without having to rebuild. It’s the first thing I included in the main function.
also include header:
#include <ctime>
Solutions very good