/// ------------------------------------------------------ /// RandomOps - (Pseudo) Random Number Generator For C# /// Copyright (C) 2003-2010 Magnus Erik Hvass Pedersen. /// Please see the file license.txt for license details. /// RandomOps on the internet: http://www.Hvass-Labs.org/ /// ------------------------------------------------------ using System; using System.Diagnostics; namespace RandomOps { /// /// Implements RNG of a circle. The method is taken from: /// [1] von Neumann, J. "Various Techniques Used in Connection with Random Digits." /// NBS Appl. Math. Ser., No. 12. Washington, DC: U.S. Government Printing Office, /// pp. 36-38, 1951. /// public abstract partial class Random { /// /// Generate a uniform random point from the unit-radius 2-dimensional circle. /// Thread-safe if Disk() is thread-safe. /// public virtual double[] Circle() { double[] x = new double[2]; Circle(out x[0], out x[1]); return x; } /// /// Generate a uniform random point from the unit-radius 2-dimensional circle. /// Thread-safe if Disk() is thread-safe. /// /// Random point x /// Random point y public virtual void Circle(out double x, out double y) { double v1, v2, s; Disk(out v1, out v2, out s); x = (v1 * v1 - v2 * v2) / s; y = 2 * v1 * v2 / s; } } }