/// <summary>Randomly generates a name using a markov process with a random number generator seeded by an input string.</summary> /// <param name="seedString">String to seed the random number generator.</param> /// <returns>A string which is appropriate for use as the name of a celestial body.</returns> public string Name(string seedString) { var word = "`"; var i = 0; var k = 0; var minLength = Random.Randint(seedString + " min length", 4, 7); var maxLength = 11; while (true) { if (word.Length == 1) { var r = Random.Rand(seedString + " initial " + k); var p = 0.0; for (var j = 0; j < 27; j++) { p += Initials[j]; if (r < p) { word += (char)(96 + j); break; } } } while (true) { var r = Random.Rand(seedString + i + k); var p = 0.0; for (var j = 0; j < 27; j++) { p += Probabilities[word[i] - 96, word[i + 1] - 96, j]; if (r < p) { word += (char)(96 + j); break; } } i++; if (word.Last().Equals('`')) { break; } } if (word.Length <= maxLength + 2 && word.Length >= minLength + 2) { return(word.Trim('`')); } word = "`"; i = 0; k++; } }
/// <summary>Initializes an instance of the Orbit class with a specified parent and random number generator belonging to the orbiting body.</summary> /// <param name="parent">The body which the orbit circumscribes.</param> /// <param name="random">The seeded random number generator belonging to the orbiting body.</param> public Orbit(Body parent, StringSeededRandom random) { Parent = parent; double minA; if (parent.Children.Count == 0) { minA = Sqrt(G * parent.Mass / Pow(10, random.Uniform("first satellite gravity", -2, 0))); } else { minA = 1.5 * parent.Children[parent.Children.Count - 1].Orbit.SemiMajorAxis; } if (parent.HasRing) { if (parent.InnerRingRadius < minA && minA < parent.OuterRingRadius) { minA = parent.OuterRingRadius; } } var maxA = 1.5 * minA; if (parent.HasRing) { if (parent.InnerRingRadius < maxA && maxA < parent.OuterRingRadius) { maxA = parent.InnerRingRadius; } } if (maxA > parent.SphereOfInfluence) { maxA = parent.SphereOfInfluence; } Eccentricity = Pow(random.Rand("eccentricity"), 10); SemiMajorAxis = random.Uniform("semi-major axis", minA, maxA); Inclination = PI / 2 * Pow(random.Rand("inclination"), 10); AscendingNode = random.Uniform("ascending node", 0, 2 * PI); ArgumentOfPeriapsis = random.Uniform("argument of ascending node", 0, 2 * PI); MeanAnomaly = random.Uniform("mean anomaly", 0, 2 * PI); Period = OrbitalPeriod(SemiMajorAxis, parent.Mass); Periapsis = Periapsis(Eccentricity, SemiMajorAxis); Apoapsis = Apoapsis(Eccentricity, SemiMajorAxis); Velocity = OrbitalVelocity(SemiMajorAxis, Period); }