Sabtu, 06 Desember 2025

ex1110.c srand() using unsigned time()

/* ex1110.c */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
    int r,a,b;

    srand((unsigned)time(NULL));
    for(a=1;a<=20;a++)
    {
        for(b=1;b<=5;b++)
        {
            r=rand();
            printf("%d\t",r);
        }
        putchar('\n');
    }
    return(0);
}

output:
 
6914    6109    24041   15261   8684
1005    9614    5745    31846   13018
24565   2804    18420   6184    3679
16881   17543   1301    18919   2475
31393   17962   15040   23      3257
16145   5311    11592   14305   30886
15641   8747    18342   21840   32109
28532   312     24466   26629   2264
18891   26333   20825   26749   3132
24233   724     1711    8696    13252
2779    31188   17178   3049    19980
21154   16851   9108    15811   2191
5391    15893   22499   2697    30293
23523   21459   18408   5871    11060
8390    17825   12364   26314   6464
5052    29602   5904    4054    14088
7383    26981   6453    23309   11426
4536    14181   24642   3566    27221
19023   6784    10879   17918   27005
21431   13015   10302   2850    26336

Process returned 0 (0x0)   execution time : 0.117 s
Press any key to continue.

Tidak ada komentar:

Posting Komentar