Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- typedef unsigned long long int RANDOM_TYPE;
- RANDOM_TYPE a, b, m, seed, randomNumber;
- struct{
- double x,y,z;
- }p;
- int main(){
- double r, xt2, arraybin[10], distanzatot, media, bin=10000;
- int position, i, c,g,passi=10000;
- i=0; media=0;
- p.x=0; p.y=0; p.z=0;
- position=0;
- i=0;
- a=16807;
- m=2147483647;
- seed=222;
- randomNumber=seed;
- FILE *ff;
- FILE *fp;
- ff=fopen("casuale.dat","w+");
- for(i=1; i<passi; i++){
- randomNumber=(a*randomNumber)%m;
- fprintf(ff,"%d %lf %lf %lf %Lu \n", i,p.x,p.y,p.z,randomNumber);
- r=(double)randomNumber/(double)m;
- if(r<(1/6.)){
- p.z+=1;
- }
- else if (r<(2/6.)){
- p.z-=1;
- }
- else if (r<(3/6.)){
- p.x+=1;
- }
- else if (r<(4/6.)){
- p.x-=1;
- }
- else if (r<(5/6.)){
- p.y+=1;
- }
- else if (r<1){
- p.y-=1;
- }
- }
- fp=fopen("dati_png.gnu","w");
- fprintf(fp, " splot 'casuale.dat' u 2:3:4 \n set xlabel 'x' \n set ylabel 'y' \n set zlabel 'z'\n set term png \n set output 'casuale.png' \n replot \n \n ");
- fclose(fp);
- system("gnuplot dati_png.gnu");
- fp=fopen("dati_ps.gnu","w");
- fprintf(fp, " plot 'casuale.dat' u 2:3:4 \n set xlabel 'x' \n set ylabel 'y' \n set zlabel 'z' \n set term post col \n set output 'eull.ps' \n replot \n \n ");
- fclose(fp);
- system("gnuplot dati_ps.gnu");
- system("rm dati_ps.gnu");
- system("rm dati_png.gnu");
- system("gnuplot>splot 'casuale.dat' u 2:3:4");
- }
Advertisement
Add Comment
Please, Sign In to add comment