Demonstrates the use of srand to generate random numbers in different series.The user asked to input a seed, and the program then generates four random numbers. The process is repeated three times
SoUrCe CoDe:
OuTpUt:
SoUrCe CoDe:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #include <iostream.h> #include <conio.h> #include <cstdlib> using namespace std; int main () { cout << " Enter random number seed: "; int seed; cin >> seed; srand ( seed ); cout << " Random number with seed " << seed <<" : " << rand () << " " << rand () << " " << rand () << " " << rand () << "\n\n\n"; cout << " Enter another random seed:"; cin >> seed ; srand ( seed ); cout << " Random numbers with seed " << seed << " : " << rand () << " " << rand () << " " << rand () << " " << rand () << "\n\n"; cout << " Enter another random seed:"; cin >> seed ; srand ( seed ); cout << " Random numbers with seed " << seed << " : " << rand () << " " << rand () << " " << rand () << " " << rand () << "\n\n"; cout << " Hope you found these numbers intresting!!! :)\n "; getch (); return 0; } // main |
OuTpUt:
Enter random number seed: 255 Enter random number seed 255 : 10966 21850 28819 871 Enter another random seed:511 Random numbers with seed 511 : 10790 7557 27899 1707 Enter another random seed: 997 Random numbers with seed 997: 7384 6025 8744 3294 Hope you found these numbers intresting!!! :)
No comments:
Post a Comment