/* 1次元ランダムウォーク */ #include #include #include main() { unsigned int seed; int nran; int i,j; int istep,nstep; float a1; float h; float x; double step; FILE *output; output = fopen("ev.dat","w"); printf("Input: seed \n"); scanf("%u", &seed); printf("Input: Number of steps:\n"); scanf("%u", &nstep); srand(seed); h=1.0; x=0.0; for(istep=0; istep < nstep; istep++){ j=rand(); a1=j/(RAND_MAX+1.0); if(a1<0.5) x=x-h; else x=x+h; printf("istep= %d, x=%.5f\n",istep,x); fprintf(output, "%d %f\n",istep,x); } return; }