File size: 1,686 Bytes
b1b3bae |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
/// ------------------------------------------------------
/// 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
{
/// <remarks>
/// 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.
/// </remarks>
public abstract partial class Random
{
/// <summary>
/// Generate a uniform random point from the unit-radius 2-dimensional circle.
/// Thread-safe if Disk() is thread-safe.
/// </summary>
public virtual double[] Circle()
{
double[] x = new double[2];
Circle(out x[0], out x[1]);
return x;
}
/// <summary>
/// Generate a uniform random point from the unit-radius 2-dimensional circle.
/// Thread-safe if Disk() is thread-safe.
/// </summary>
/// <param name="x">Random point x</param>
/// <param name="y">Random point y</param>
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;
}
}
}
|