// generate n random particles in the unit square // writes a particle2 file to output // can be piped into nbody program, e.g. "randsq 10 1 10 | nbody ." #include #include #include #include double frand() { // return a random number between 0 and 1 return rand()/32767.; } void main(int argc, char **argv) { if (argc!=4) { fprintf(stderr, "Usage: randsq \n"); exit(1); } int n = atoi(argv[1]); double maxspeed = atof(argv[2]); double mass = atof(argv[3]); int i; printf("particle2\n# randsq %d %g %g\nm %g\n", n, maxspeed, mass, mass); int seed = time(0); fprintf(stderr, "random seed=%d\n", seed); srand(seed); for (i=0; i