?? random.txt
字號:
#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 + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -