C++ Programming Code Examples C++ > Beginners Lab Assignments Code Examples C++ Programming Code to Generate Different Random Numbers C++ Programming Code to Generate Different Random Numbers To generate random numbers in C++ programming, use the function rand() to generate and print random numbers. And if you want to generate different-different random numbers at each time when you compile and run the same program, then use the function srand() before generating the random numbers using the function rand() as shown here in the following program. #include<iostream.h> #include<stdlib.h> #include<conio.h> void main() { clrscr(); srand(); int i; for(i=0; i<20; i++) { cout<<rand()<<"\t"; } getch(); }