SHARE
TWEET

Untitled

a guest Jul 17th, 2017 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package randPlanets;
  2.  
  3. import java.io.FileWriter;
  4. import java.io.IOException;
  5. import java.io.PrintWriter;
  6. import java.util.Random;
  7.  
  8. public class Main {
  9.  
  10.     static int numPlanets = 100;
  11.  
  12.     static double maxCoordinate = 100;
  13.     static double maxVel = 100;
  14.     static double maxMass = 100;
  15.  
  16.     static boolean constMass = true;
  17.  
  18.     /**
  19.      * @param args
  20.      * @throws IOException
  21.      */
  22.     public static void main(String[] args) throws IOException {
  23.  
  24.         PrintWriter out = new PrintWriter(new FileWriter("Planets.txt"));
  25.  
  26.         Random generator = new Random();
  27.  
  28.         for (int i = 0; i < numPlanets; i++) {
  29.  
  30.             double x, y, z;
  31.  
  32.             x = negative() * Math.random() * maxCoordinate;
  33.             y = negative() * Math.random() * maxCoordinate;
  34.             z = negative() * Math.random() * maxCoordinate;
  35.  
  36.             double velx, vely, velz;
  37.  
  38.             velx = negative() * generator.nextDouble() * maxVel;
  39.             vely = negative() * generator.nextDouble() * maxVel;
  40.             velz = negative() * generator.nextDouble() * maxVel;
  41.  
  42.             double mass;
  43.  
  44.             if (constMass) {
  45.                 mass = maxMass;
  46.             } else {
  47.                 mass = Math.random() * maxMass;
  48.             }
  49.  
  50.             out.println(mass + " " + x + " " + y + " " + z + " " + velx + " "
  51.                     + vely + " " + velz);
  52.         }
  53.         out.close();
  54.  
  55.     }
  56.  
  57.     static double negative() {
  58.         double neg;
  59.  
  60.         if (Math.random() < 0.5) {
  61.             neg = 1.0;
  62.         } else {
  63.             neg = -1.0;
  64.         }
  65.         return neg;
  66.     }
  67.  
  68. }
RAW Paste Data
Top