Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- double uniform_rand(void) {
- return rand() / ((double) RAND_MAX + 1.);
- }
- double normal_rand_sub(void) {
- double z = 0.;
- int i;
- for (i = 0; i < 12; i++)
- z += uniform_rand();
- return z - 6.;
- }
- double normal_rand(double ave, double sd) {
- return sd * normal_rand_sub() + ave;
- }
- int main(void) {
- const int section = 101;
- int i, j, n = 3000, spec, freq[section];
- double ave = 50., sd = 10.;
- for (i = 0; i < section; i++)
- freq[i] = 0;
- for(i = 0; i < n; i++) {
- spec = (int) normal_rand(ave, sd);
- if (spec < 0) freq[0]++;
- else if (spec > section - 1) freq[section - 1]++;
- else freq[spec]++;
- }
- for (i = 0; i < section; i++) {
- printf("%3d - ", i);
- for (j = 0; j < freq[i]; j++)
- printf("*");
- puts("");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement