模拟p-坚持CSMA算法

#include 
#include 
#include 

int main()
{
  srand(time(NULL));
  while(1)
    {
      if((double)rand()/RAND_MAX)
	{
	  printf("Send message allowed.\n");
	  if(rand()/(RAND_MAX/2)>0.5)
	    {
	      printf("Message have been sent.\n");
	    }
	  else
	    {
	      printf("Please wait a minute.\n");
	    }
	}
      else
	{
	  printf("You are not allowed to send message.\n");
	}
    }
}

结果如下:

模拟p-坚持CSMA算法_第1张图片

你可能感兴趣的:(模拟p-坚持CSMA算法)