File:  [MW Coherent from dump] / coherent / d / usr / src / examples / rand.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:38 2019 UTC (7 years, 2 months ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent

#define MAXVAL 32767	/* range of rand: [0,2^15-1] */

main(argc, argv)
int argc; char *argv[];
{
	register int i, hits, threshold, ntrials;

	hits = 0;
	threshold = (argc > 1) ? atoi(argv[1]) : MAXVAL/2;
	ntrials = (argc > 2) ? atoi(argv[2]) : 1000;
	if (argc > 3)
		srand(atoi(argv[3]));

	for (i = 1; i <= ntrials; i++)
		if (rand() > threshold)
			++hits;

	printf("%d values above %d in %d trials (%ld%%).\n",
		hits, threshold, ntrials, (100L*hits)/ntrials);
}


unix.superglobalmegacorp.com

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