Annotation of coherent/d/usr/src/examples/rand.c, revision 1.1.1.1

1.1       root        1: #define MAXVAL 32767   /* range of rand: [0,2^15-1] */
                      2: 
                      3: main(argc, argv)
                      4: int argc; char *argv[];
                      5: {
                      6:        register int i, hits, threshold, ntrials;
                      7: 
                      8:        hits = 0;
                      9:        threshold = (argc > 1) ? atoi(argv[1]) : MAXVAL/2;
                     10:        ntrials = (argc > 2) ? atoi(argv[2]) : 1000;
                     11:        if (argc > 3)
                     12:                srand(atoi(argv[3]));
                     13: 
                     14:        for (i = 1; i <= ntrials; i++)
                     15:                if (rand() > threshold)
                     16:                        ++hits;
                     17: 
                     18:        printf("%d values above %d in %d trials (%ld%%).\n",
                     19:                hits, threshold, ntrials, (100L*hits)/ntrials);
                     20: }
                     21: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.