Lines Matching +full:high +full:- +full:threshold
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
6 * biastest.c -- bias test for arc4random_uniform().
9 * (3/4) * UINT32_MAX, which should give a high amount of bias in
41 fprintf(stderr, "usage: %s [-n tries] [-t upper_bound]\n", argv0); in usage()
48 uint32_t threshold = 3UL << 30; in main() local
59 threshold = (uint32_t)atoll(optarg); in main()
69 if (threshold == 0) { in main()
70 fprintf(stderr, "threshold must be between 1 and %lu\n", (unsigned long)UINT32_MAX); in main()
74 sample = calloc(threshold, 1); in main()
76 perror("calloc(threshold, 1)"); in main()
80 collect_sample(sample, tries, threshold); in main()
81 analyze_sample(sample, tries, threshold); in main()
99 collect_sample(unsigned char *sample, long long tries, uint32_t threshold) in collect_sample() argument
108 x = arc4random_uniform(threshold); in collect_sample()
110 assert(x < threshold); in collect_sample()
127 analyze_sample(const unsigned char *sample, long long tries, uint32_t threshold) in analyze_sample() argument
138 for (i = 0; i < threshold; i++) { in analyze_sample()
146 median = threshold; in analyze_sample()
153 for (i = 0; i < threshold; i++) { in analyze_sample()
154 discrepancy = i - average; in analyze_sample()
158 if (median == threshold && n > tries / 2) in analyze_sample()
171 assert(median < threshold); in analyze_sample()
173 printf("\tthreshold: %lu\n", (unsigned long)threshold); in analyze_sample()
177 printf("\tmedian: %lld (expected %lu)\n", median, (unsigned long)threshold / 2); in analyze_sample()
178 printf("\taverage: %f (expected %f)\n", average, 0.5 * (threshold - 1)); in analyze_sample()
180 sqrt(((double)threshold * threshold - 1.0) / 12)); in analyze_sample()
186 average = (double)tries / threshold; in analyze_sample()
190 discrepancy = i - average; in analyze_sample()
194 variance /= threshold; in analyze_sample()
200 if (n >= threshold / 2) { in analyze_sample()
210 …printf("\tdeviation: %f (expected %f)\n\n", sqrt(variance), sqrt(average * (1.0 - 1.0 / threshold)… in analyze_sample()