

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ Program to Generate Random Numbers Using Probability Distribution Function
Probability Density Function (pdf), is a function that describes the relative likelihood for this random variable to take on a given value. It is also called as density of a continuous random variable.
The probability of the random variable fall within a particular range of values is given by the integral of this variable’s density over that range, So, it is given by the area under the density function but above the horizontal axis and between the lowest and greatest values of the range. Probability Distribution is based upon this probability density function.
Algorithm
Begin Declare n Assign pdf=0 For i =0 to n , do pdf = rand() mod 200 If pdf greater than 360 Print 1 Else if pdf less than 0 Print 0 Else Print pdf * 0.1 / 360 Done Done end
Example Code
#include <iostream> using namespace std; int n = 6; int main(int argc, char **argv) { int pdf = 0; for (int i = 0; i < n; i++) { pdf = rand() % 200; if (pdf > 360) cout << 1 << " "; else if (pdf < 0) cout << 0 << " "; else cout << pdf * 0.1 / 360 << " "; } cout << "..."; }
Output
0.0508333 0.0238889 0.0491667 0.0319444 0.0536111 0.0375 ...
- Related Questions & Answers
- Generate random numbers following a normal distribution in C/C++
- Java program to generate random numbers
- C# program to generate secure random numbers
- Java Program to generate random numbers string
- Generate random numbers using C++11 random library
- C++ Program to Generate Random Numbers Using Middle Square Method
- Java Program to generate n distinct random numbers
- C++ Program to Generate Random Numbers Using Multiply with Carry Method
- Java Program to generate random numbers with no duplicates
- Generate random numbers in Arduino
- How to generate a probability density distribution from a set of observations in R?
- Python module to Generate secure random numbers
- Generate Secure Random Numbers for Managing Secrets using Python
- How does Python generate random numbers?
- Generate pseudo-random numbers in Python
Advertisements