+
+/**
+ * @function Split_System
+ * @purpose Helper to divide one system into an array of systems
+ * Each sub system will have N = (s->N / n) bodies in it
+ * @param s - The original system (typically &universe)
+ * @param n - The number of sub systems in the array
+ *
+ * WARNING: It is the caller's responsibility to free() the returned array
+ */
+System * Split_System(System * s, unsigned n)
+{
+ System * result = (System*)(calloc(n, sizeof(System)));
+ if (result == NULL)
+ {
+ perror("Couldn't create array of sub systems");
+ exit(EXIT_FAILURE);
+ }
+
+ unsigned n_per_system = (s->N) / n;
+ unsigned remainder = (s->N) % n;
+
+ for (unsigned i = 0; i < n; ++i)
+ {
+ result[i].N = n_per_system;
+ if (i == n-1)
+ result[i].N += remainder;
+ result[i].body = (s->body) + (n_per_system * i);
+ result[i].steps = 0;
+ }
+ return result;
+}
+
+/**
+ * @function System_Random
+ * @purpose Randomly generate initial body field
+ * @param s - The system
+ * @param n - Number of bodies
+ */
+void System_Random(System * s, int n)
+{
+ srand(0);
+ s->N = (unsigned)n;
+ s->body = (Body*) calloc((size_t)s->N, sizeof(Body));
+ s->steps = 0;
+
+ s->body[0].mass = 1e11;
+
+ for (unsigned a = 1; a < s->N; ++a)
+ {
+ s->body[a].mass = 1e7;
+ for (unsigned i = 0; i < DIMENSIONS; ++i)
+ {
+ s->body[a].x[i] = -10000 + rand() % 20000;
+ s->body[a].v[i] = -2 + rand() % 4;
+ }
+ s->body[a].v[2] = 0;
+ s->body[a].x[2] = 0; //set z to zero; force in plane
+
+ }
+}