Skip to content

Instantly share code, notes, and snippets.

@bricef
Created March 26, 2013 17:37
Show Gist options
  • Save bricef/5247433 to your computer and use it in GitHub Desktop.
Save bricef/5247433 to your computer and use it in GitHub Desktop.
/* random.c */
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void parser(char *input, double particles[][4]){
sscanf(
input,
"p[20] = nullvector(%lf,%lf,%lf,%lf)",
&particles[20][3], &particles[20][0],
&particles[20][1], &particles[20][2]
);
printf(
"energy: %E, p: (%E, %E, %E)\n",
particles[20][3], particles[20][0],
particles[20][1], particles[20][2]
);
}
int main(){
double particles[22][4];
int seed,i,x,y;
double px_buf, py_buf, pz_buf;
seed=time(NULL);
srand(seed);
/* The random numbers are generated between 1E-12 and 10E-12 */
/*Double precision floats support up to 15 decimal places*/
for(i=0;i<20;i++){
px_buf=((double)rand()/RAND_MAX)*9001E-15;
py_buf=((double)rand()/RAND_MAX)*9001E-15;
pz_buf=((double)rand()/RAND_MAX)*9001E-15;
particles[0][i]=px_buf;
particles[1][i]=py_buf;
particles[2][i]=pz_buf;
printf("(step: %i) The following noise momentum was generated: (%.15E,%.15E,%.15E)\n",i,px_buf,py_buf,pz_buf);
}
parser("p[20] = nullvector(45.0000000000106,33.03951484238976,14.97124733712793,26.6317895033428)", \
particles);
for(y=0;y<22;y++){
for(x=0;x<3;x++){
printf("%.15E \t", particles[x][y]);
}
printf("\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment