SRL Archive - SRL Snippets

RandomBinom


CynicRus

2013-02-26 13:09:12


function RandomBinom(n, p: Extended): Extended;
var
x: Extended;
i: Integer;
begin
x := 0;
for i := 1 to Round(n) do
if Random - p <= 0 then x := x + 1;
Result := x
end;

Cheers,
Cynic.

Kevin

2013-02-26 13:19:51

I understand what this is and what it's doing, but what's the use case of this for srl?

And why make n an extended variable as opposed to an Integer or LongInt since it's rounded anyway?

And then side-question, what's the range on Random when it isn't passed an integer value?

Edit: Use case would make sense as a random number with a binomial distribution. Doesn't GaussRand() cover that though?

Turpinator

2013-02-28 14:14:58

From: nivek1989
Edit: Use case would make sense as a random number with a binomial distribution. Doesn't GaussRand() cover that though?


Gaussian/Normal Distribution is continuous whereas a Binomial Distribution is discrete (only allowing for specified values like an integer range).
Allsooo… Binomial is used to 'count the number of successes until failures' in a line of independent success/fail experiments.
So, they have different applications.

Kevin

2013-02-28 14:54:28

From: Turpinator
Gaussian/Normal Distribution is continuous whereas a Binomial Distribution is discrete (only allowing for specified values like an integer range).
Allsooo… Binomial is used to 'count the number of successes until failures' in a line of independent success/fail experiments.
So, they have different applications.


This isn't counting the number of successes until failure however, this is counting the total number of successes over n times. Maybe I'm misunderstanding something, but this does not seem to break at the first failure, so many failures would likely occur over the course of this count? So what I do seem to gather is this is roughly the same as a Gaussian distribution, however focused on an Integer return, which could be done via Round(Gauss())?

Gala

2013-03-01 13:27:34

From: nivek1989
So what I do seem to gather is this is roughly the same as a Gaussian distribution, however focused on an Integer return, which could be done via Round(Gauss())?


For "low" values it isn't even roughly Gaussian.