D
D
di2019-03-11 12:00:28
PHP
di, 2019-03-11 12:00:28

How to implement Poisson stream?

I'm trying to implement the algorithm taken from here https://life-prog.ru/1_13833_puassonovskiy-potok.html (Fig. 28.6)
I get a completely different result (1-digit number instead of 33)
My code

<?php
$lambda = 8 / 24;
$Tn = 100;

$t = 0;
$N = 0;
do {
     $r = rand(0,1);
     $temp = (-1 / $lambda) * log($r);
     $t = $t + $temp;
     $N = $N + 1;
            //echo $t;
} while ($t <= $Tn);
var_dump($N);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
@
@pestunov, 2019-03-11
@Delgus

The problem here is:
rand() returns 0 or 1
We need to do something like
$r = rand(0, 100)/100;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question