random.txt
来自「在用计算机编制程序时」· 文本 代码 · 共 96 行
TXT
96 行
#include <stdio.h>
#include <math.h>
#define S 2
float Xn=12345;//Seed & Iter
float Rn;//Return Val
void InitSeed(float inX0)
{
Xn=inX0;
}
/*
Xn+1=(Xn^2/10^s)(mod 10^2s)
Rn+1=Xn+1/10^2s
*/
float MyRnd()
{
Xn=(int)fmod((Xn*Xn/pow(10,S)),pow(10,2*S));//here can's use %
Rn=Xn/pow(10,2*S);
return Rn;
}
/*测试主程序,注意,这里只列举一次测试主程序,以下不再重复*/
int main()
{
int i;
FILE * debugFile;
if((debugFile=fopen("outputData.txt","w"))==NULL)
{
fprintf(stderr,"open file error!");
return -1;
}
printf("\n");
for(i=0;i<100;i++)
{
tempRnd=MyRnd();
fprintf(stdout,"%f ",tempRnd);
fprintf(debugFile,"%f ",tempRnd);
}
getchar();
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?