Vector2 RandomSize(Config config, int[] areaCount) { int area; if (config.useGaussianDistribution) { float t; do { t = GaussianDistribution.Next(config.mean, config.deviation); } while (t < 0f || t > 1f); t = 2f * Mathf.Abs(t - 0.5f); area = (int)Mathf.Lerp(config.minArea, config.maxArea, t); } else { area = UnityEngine.Random.Range(config.minArea, config.maxArea + 1); } ++areaCount[area - config.minArea]; float asqrt = Mathf.Sqrt(area); int l = Mathf.Max(1, Mathf.FloorToInt(asqrt)); int r = Mathf.CeilToInt(asqrt) + 1; float width = UnityEngine.Random.Range(l, r); float length = area / width; return(new Vector2(width, length)); }
/// <summary> /// Attempts to connect to data input source. /// </summary> protected override void AttemptConnection() { m_nextPublicationTime = ToPublicationTime(DateTime.UtcNow.Ticks); m_nextPublicationTimeWithLatency = m_nextPublicationTime + (long)(m_latency.Next() * TimeSpan.TicksPerMillisecond); if ((object)m_timer == null) { m_timer = new ScheduledTask(ThreadingMode.ThreadPool); m_timer.Running += m_timer_Running; } if ((object)m_statusUpdate == null) { m_statusUpdate = new ScheduledTask(ThreadingMode.ThreadPool); m_statusUpdate.Running += m_statusUpdate_Running; } m_timer.Start(); m_statusUpdate.Start(10000); }
public void GenerateValues() { GaussianDistribution r = new GaussianDistribution(0, 1, -1, 1); StringBuilder sb = new StringBuilder(); for (int x = 0; x < 10000; x++) { sb.AppendLine(r.Next().ToString()); } Clipboard.SetText(sb.ToString()); }
void NormalDistribution() { int[] list = new int[columns]; for (int i = 0; i < samples; ++i) { float v = GaussianDistribution.Next(mean, deviation); if (v < 0f || v > 1f) { continue; } int c = (int)(v * columns); ++list[c]; } Show(list); }