Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package randPlanets;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.Random;
- public class Main {
- static int numPlanets = 100;
- static double maxCoordinate = 100;
- static double maxVel = 100;
- static double maxMass = 100;
- static boolean constMass = true;
- /**
- * @param args
- * @throws IOException
- */
- public static void main(String[] args) throws IOException {
- PrintWriter out = new PrintWriter(new FileWriter("Planets.txt"));
- Random generator = new Random();
- for (int i = 0; i < numPlanets; i++) {
- double x, y, z;
- x = negative() * Math.random() * maxCoordinate;
- y = negative() * Math.random() * maxCoordinate;
- z = negative() * Math.random() * maxCoordinate;
- double velx, vely, velz;
- velx = negative() * generator.nextDouble() * maxVel;
- vely = negative() * generator.nextDouble() * maxVel;
- velz = negative() * generator.nextDouble() * maxVel;
- double mass;
- if (constMass) {
- mass = maxMass;
- } else {
- mass = Math.random() * maxMass;
- }
- out.println(mass + " " + x + " " + y + " " + z + " " + velx + " "
- + vely + " " + velz);
- }
- out.close();
- }
- static double negative() {
- double neg;
- if (Math.random() < 0.5) {
- neg = 1.0;
- } else {
- neg = -1.0;
- }
- return neg;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement