0% found this document useful (0 votes)
71 views

Random Number Generator

This C++ program uses the rand() function and srand() with time() to generate 10 random numbers between 0 and 1000 each time the program is run. It includes the iostream, ctime libraries and namespaces std, initializes an integer k to seed the random number generation, defines a random() function that generates a random number modulo k and prints it, increments k, and calls random() 10 times in a for loop in main.

Uploaded by

Saif khawaja
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

Random Number Generator

This C++ program uses the rand() function and srand() with time() to generate 10 random numbers between 0 and 1000 each time the program is run. It includes the iostream, ctime libraries and namespaces std, initializes an integer k to seed the random number generation, defines a random() function that generates a random number modulo k and prints it, increments k, and calls random() 10 times in a for loop in main.

Uploaded by

Saif khawaja
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Random number generator

#include <iostream> #include <ctime> //to generate different random number every time you run a program using namespace std; int k=1000; void random() { int r; srand(time(0)); r = rand()%k; cout<<r<<endl; k++; } int main() { for(int i=0;i<10;i++) { random(); } }

//for

random number

You might also like