binomial distribution in csharp

To calculate the binomial distribution in C#, you can use the MathNet.Numerics library. Here's an example code:

main.cs
using MathNet.Numerics.Distributions;

...

int n = 10; // number of trials
double p = 0.5; // probability of success
int k = 3; // number of successes

double prob = Binomial.PMF(n, p, k); // calculate the binomial probability mass function

Console.WriteLine($"Binomial probability for {k} successes out of {n} trials with probability of success {p} is {prob}.");
366 chars
12 lines

This will output:

main.cs
Binomial probability for 3 successes out of 10 trials with probability of success 0.5 is 0.1171875.
100 chars
2 lines

Binomial.PMF calculates the probability mass function (PMF) of the binomial distribution for the given parameters n, p, and k. n is the number of trials, p is the probability of success, and k is the number of successes.

gistlibby LogSnag