This is a C Program to generate random numbers using Probability Distribution Function.The probability density function of a continuous random variable is a function which can be integrated to obtain the probability that the random variable takes a value in a given interval.
Here is source code of the C Program to Generate Random Numbers Using Probability Distribution Function. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <math.h>
#include <stdlib.h>
//This is a sample program to generate a random numbers based on probability desity function of spiner
//pdf(x) = 1 if x>360
// = 0 if x<0
// = x/360 otherwise
int N = 10;
int main(int argc, char **argv) {
int p = 0, i;
for (i = 0; i < N; i++) {
p = rand() % 400;
if (p > 360)
printf("%d ", 0);
else if (p < 0)
printf("%d ", 0);
else
printf("%f ", p * 0.1 / 360);
}
printf("...");
return 0;
}
Output:
$ gcc ProbabilityDist.c $ ./a.out 0.011389 0.018611 0.092778 0.027778 0 0.034444 0.077222 0.043889 0.045000 0.017778 ...
Sanfoundry Global Education & Learning Series – 1000 C Programs.
advertisement
advertisement
Here’s the list of Best Books in C Programming, Data Structures and Algorithms.
If you find any mistake above, kindly email to [email protected]Related Posts:
- Watch Advanced C Programming Videos
- Practice Computer Science MCQs
- Apply for C Internship
- Practice BCA MCQs
- Check C Books