rand() & srand() ---------------- the element of chance can be introduced into compiler application by using the standard library function rand. ex: i = rand(); the function rand generates an unsigned integer between 0 and rand_max(a symbolic constant defined in the ) The valume of rand_max must be at least 32767-the maximum positive value for two_byte integer. If rand truly produces integer at random, every number between 0 and rand_max has an equal chance(or probability) of being chosen each time. rand is called the range of values produced directly by rand is often different than what is needed in a specific application. for example, a program that simulates coin tossing might require only 0 for heads and 1 for tails; rolling a six-sided dice would require random integers in range 1 to 6. * to produce integers in the range 0 to 5, we use the modulus operatior(%) in conjunction with rand as follows: rand % 6 this is called scaling. the number 6 is called the scaling factor. we shift range of numbers produced by adding 1, hence confirm that the results are in the range 1 to 6. ------------------------------------------------ #include #include int main() { int random_integer = rand(); for (int i = 0; i <10; i++) { random_integer = rand(); cout << random_integer << endl; } return 0; } ------------------------------------------------ #include #include #include int main() { for (int i = 1; i <= 10; i++) { cout << setw(10) << (i + rand()%6); cout << endl; } return 0; } ------------------------------------------------ #include #include #include int main() { for (int i = 1; i <= 20; i++) { cout << setw(10) << (i + rand()%6); if (i%5 == 5) cout << endl; } return 0; } ------------------------------------------------- #include #include #include int main() { unsigned seed; cout <<"Enter seed: "; cin >> seed; srand(seed); for(int i = 1; i <=10; i++) { cout << setw(10) <<(1 + rand()%6); cout << endl; } return 0; } -------------------------------------------------- #include #include #include int main() { srand((unsigned)time(0));/*this causes the computer to read its clock to obtain the value for the seed automatically the time function(with 0 as written in the proceding statement), return the current calendar time in seconds. this value is converted to an unsigned rundom number generator. the function prototype for time is in or */ int random_integer; for (int index=0; index<10; index++) { random_integer = rand(); cout << random_integer << endl; } return 0; } =================================================== due wednesday:: u work for the lotter commition, commition requests that u create a program to display on screen 6 different numbers.range from 1 to 59, the sixth number is the BONUS number..please indicate