Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I try to make random loss from a given bit stream. Assume that I have a bit stream as

10 01 10 11 00

Now I will create a code to implement random loss. The function with two inputs are original bit stream and percent loss. Output function is output bit stream

int* bitloss(int* orbit,int size_orbit,float loss_percent)
{
srand(time(NULL));
int* out_bitstream=(int*)malloc(sizeof(int)*size_orbit);
double randval ;
for(int i=0;i<size_orbit,i++)
{
    randval = (double)rand()/(double)RAND_MAX;
    if(randval<loss_percent) 
         out_bitstream[i]=-1;
     else out_bitstream[i]=orbit[i];

}
return out_bitstream;
}

This code will change value of original bit to -1 if the random belows than loss_percent.I call -1 bit is loss bit. So given loss_percent equals 20%. That mean I will loss 2 packets from 10 original bits. But when I do it. I show that some time I loss 0 bit, some time 4 bit, and sometime 2 bit. It is not stable. How to edit my code to stable loss. For example, I want to loss 20%. So the number of -1 bits are 2. Thank you so much

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
198 views
Welcome To Ask or Share your Answers For Others

1 Answer

Assuming each bit has a probability p of being lost, and that bit loss are independent (this may not be the case in for example some fading channels where bit loss are more likely to occur in bursts), the number of bit lost in N bits follows a binomial distribution.

Thus, for 10 bits and a loss rate of 20%, you would get the following distribution: B(10,0.2)

Similarly, for 1000 bits and the same loss rate of 20%, you would get the following distribution: B(1000,0.2)

Note that as the total number of bits gets larger, the binomial distribution approaches a Gaussian distribution with average Np and variance Np(1-p) . Specifically, for the case of N=1000 and p=0.2 overlapping the Gaussian distribution over the binomial distribution gives: enter image description here

As you can see it is a pretty good approximation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...