📄 mypn.cpp
字号:
#include <stdio.h>
#include <fstream.h>
#include <stdlib.h>
#define MYPNLEN 4000000
#define REGLEN 32
unsigned int ap(unsigned int a,unsigned int b);
void shift(void);
void youcheng();
unsigned int A,B,temp,stemp;
unsigned int outdata[MYPNLEN];
unsigned int ab[REGLEN];
unsigned int c[REGLEN]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
int YC[50];
void main()
{
FILE *stream;
stream = fopen( "mypn", "w+t" );
int i,k,kk;
kk=1;
A=19434;B=105;
temp=B&1;
for (i=0;i<MYPNLEN;i++)
{
/* unsigned int ttt;
ttt=A+1;
if (REGLEN<32) ttt=ttt&((kk<<REGLEN)-1);
if (A==0) A+=2;
if (ttt==0) A+=2;
ttt=B+1;
if (REGLEN<32) ttt=ttt&((kk<<REGLEN)-1);
if (B==0) B+=2;
if (ttt==0) B+=2;
*/
if (temp==0)
{
B=A^B;
if (REGLEN<32) B=B&((kk<<REGLEN)-1);
}
else
{
A=A^B;
if (REGLEN<32) A=A&((kk<<REGLEN)-1);
}
shift();
temp=B&1;
cout<<temp;
outdata[i]=temp;
}
//输出,平衡性
k=0;
for (i=0;i<MYPNLEN;i++)
{
fwrite( &outdata[i], sizeof( int ), 1, stream );
if (outdata[i]==1) k++;
}
fclose( stream );
cout<<"\n1的个数"<<k<<"\n";
//游程特性:
youcheng();
for (i=1;i<=49;i++)
{
cout<<"游程YC"<<i<<" "<<YC[i]<<"\n";
}
}
void shift(void)
{
int i;
unsigned int tt,kk;
kk=1;
if (temp==0) stemp=A;
else stemp=B;
for (i=0;i<REGLEN;i++)
{
ab[i]=stemp&(kk<<i);
ab[i]=(ab[i]>>i);
}
tt=ab[0]*c[0];
for (i=0;i<(REGLEN-1);i++)
{
tt=ap(tt,ab[i+1]*c[i+1]);
}
stemp=(stemp<<1);
if (REGLEN<32) stemp=stemp&((kk<<REGLEN)-1);
stemp=stemp|tt;
if (temp==0) A=stemp;
else B=stemp;
}
unsigned int ap(unsigned int a,unsigned int b)
{
unsigned int x,y,z;
x=a;y=b;
if ((x+y)==1) z=1;
else z=0;
return z;
}
void youcheng()
{
int a,nyc;
unsigned int temp1;
temp1=outdata[0];nyc=0;
for (a=0;a<=49;a++) YC[a]=0;
for (a=0;a<=(MYPNLEN-1);a++)
{if (outdata[a]==temp1) nyc=nyc+1;
else
{temp1=outdata[a];
YC[nyc]=YC[nyc]+1;
nyc=1;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -