[Live-devel] Simulation and packet loss, part two
Tim Stabrawa
stabrawa at stanford.edu
Sat Mar 3 17:56:24 PST 2007
Antonio Tirri wrote:
> Hi, i tried to substitute the code:
>
> #ifdef TEST_LOSS
> if ((our_random()%10) != 0) // simulate 10% packet loss #####
> #endif
>
>
> with the code:
>
> //#ifdef TEST_LOSS
> if (((double)our_random()%10000)/10000.0 <= 0.8) // simulate 10% packet loss #####
> //#endif
>
> How can i edit the code in order to introduce the packet loss rate in correct way?
>
This should do it:
if ((our_random()%5) != 0) // simulate 20% packet loss #####
If you need something more flexible, read up on what range of numbers
come out of our_random() and do something like this:
if (our_random() > OUR_RAND_MAX * 0.2) // simulate 20% packet loss #####
Good luck ...
- Tim
More information about the live-devel
mailing list