⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.c

📁 产生一个满足泊松分布的随机序列信号。用于通信系统的信源部分
💻 C
字号:
//MultipleMethod mid mothed
//Possibility Possion Distribute by Distribute Rule
#include <stdio.h>
#include <math.h>

#define Lamda 3125

float Xn=12345;//Seed & Iter
float Rn;//Return Val
double long  M;

float G_PossionUp;

void InitSeed(float inX0)
{
	Xn=inX0;
}

/*
	Xn+1=Lamda*Xn(mod M)
	Rn+1=Xn/M
*/

float MyRnd()
{
		Xn=fmod(Lamda*Xn,M);//here can's use % 
		Rn=Xn/M;
		return Rn;
}


/*-------------------------------------*/

void initPossion(float lamda)
{
    float lamda_Power;
    float k_Factorial;
    
   /*First iterator ,no need.
    lamda_Power=1;
    k_Fractorial=1;
    */
    lamda_Power=lamda;
    k_Factorial=1;
   
    if(lamda_Power>1)
    {   
        while(lamda_Power<=k_Factorial)
            {
                       k_Factorial*=(k_Factorial+1); 
                       lamda_Power*=lamda;
            }
     }                           
    
    G_PossionUp=lamda_Power/k_Factorial*exp(-lamda);
}

float funPossion()
{		
		float temp;
		int count;
		
		
		count=-1;
		do
		{	
			temp=MyRnd();
			count++;	
		}while(temp>G_PossionUp);
		
		
		return count;
}

/*-------------------------------------*/



int main()
{
	   int i;
		FILE * debugFile;
		
		if((debugFile=fopen("outputData.txt","w"))==NULL)
		  {
            fprintf(stderr,"open file error!");
            return -1;
          }    
		
        printf("\n");
	
		//init proper argu number
		M=pow(2,35)-31;
		
		//determine up limit
		
		
		initPossion(10);
	
		for(i=0;i<300;i++)
		{
		    
        	fprintf(stdout,"%f ",funPossion());
			fprintf(debugFile,"%f ",funPossion());
		}			
		getchar();
		
		return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -