C language application

xiaoxiao2021-03-06  90

========================================

Example 1:

#include #include int main (void) {INT I; Printf ("Ten Random Numbers from 0 to 99 / N / N"); for (i = 0; i <10; i ) Printf ("% D / N", RAND ()% 100); return 0;} ============================ ======== Example 2: The following is an example of MSDN:

// crt_rand.c / * This Program Seeds the Random-Number Generator * with the Time, The Displays 10 Random Integers. * /

#include #include #include

INT main (void) {INT I;

/ * Seed the random-number generator with current time so tria * The number we run. * / Srand ((unsigned) TIME (NULL);

/ * Display 10 NumBers. * / For (i = 0; i <10; i ) Printf ("% 6d / n", rand ());} =============== ================

Example 1: The resulting random number is the same, run in a single program, such as: for loop, each cycle is still different. Just run this program again, the same. Example 2: Produce The random number is not the same. Why? Isn't there an English help? SRAND (NULL)); is a seed to the random number, we call him a seed. Time value every time Different. So, the seed is different, so ... The random number generated is different .. On this truth. Before calling the rand, it is best to use one person SRAND (int X); That's ALL

转载请注明原文地址:https://www.9cbs.com/read-95332.html

New Post(0)