Maths.PseudoRandom

public static class Maths.PseudoRandom
Central utilities for creating random engines and random collections.

Methods

CirclesOnDiscFibonacci

#
public static Circle[] CirclesOnDiscFibonacci(Circle disc, int count, CancellationToken token)
Create a circle packing on the interior of a disc.
disc (Circle)Disc to populate.
count (int)Number of circles.
token (CancellationToken)Cancellation token.

CirclesOnDiscHexagonal

#
public static Circle[] CirclesOnDiscHexagonal(Circle disc, int count, CancellationToken token)
Create a hexagonal pattern of circles with radius 1 around the origin.
disc (Circle)
count (int)
token (CancellationToken)

CirclesOnDiscOctagonal

#
public static Circle[] CirclesOnDiscOctagonal(Circle disc, int count, CancellationToken token)
Create an octogonal pattern of circles with varying radii around the origin.
disc (Circle)
count (int)
token (CancellationToken)

CirclesOnDiscSquare

#
public static Circle[] CirclesOnDiscSquare(Circle disc, int count, CancellationToken token)
Create a hexagonal pattern of circles with radius 1 around the origin.
disc (Circle)
count (int)
token (CancellationToken)

CirclesOnDiscStacked

#
public static Circle[] CirclesOnDiscStacked(Circle disc, int count, CancellationToken token)
Create a circle packing on the interior of a disc.
disc (Circle)Disc to populate.
count (int)Number of circles.
token (CancellationToken)Cancellation token.

CirclesOnSphericalPoints

#
public static Circle[] CirclesOnSphericalPoints(double[] x, double[] y, double[] z, CancellationToken token, double initialRadius = Infinity)
Place circles on point coordinates assumed to lie on a sphere with origin at (0,0,0).
x (double[])Point X coordinates.
y (double[])Point Y coordinates.
z (double[])Point A coordinates.
token (CancellationToken)Cancellation token.
initialRadius (double = Infinity)Initial radius to beat.
Array of non-intersecting circles.

CreateRandomEngine

#
public static Random CreateRandomEngine(Engine algorithm, int seed)
Create a new instance of a specific generator.
algorithm (Maths.Engine)Engine to use. The System engine cannot be instantiated this way.
seed (int)Seed value.
Non-threadsafe random number generator.

DilatePointsWithinBox

#
public static void DilatePointsWithinBox(ref Point3d[] points, int count, Interval length, Interval width, Interval height, Point3d origin)
Dilates the specified array of 3D points outward from a given origin so that all points remain within the defined box dimensions, and retains only the specified number of points closest to the origin after dilation.
Remarks: If the number of points in the array is less than or equal to the specified count, the method does not modify the array. The order of points in the resulting array may differ from the original order.
points (ref Point3d[])A reference to an array of Point3d structures representing the points to be dilated. The array is modified in place to contain only the closest points after dilation.
count (int)The number of points to retain after dilation. Must be less than or equal to the length of the points array.
length (Interval)An Interval that defines the allowable range for the x-coordinates of the box within which the points will be dilated.
width (Interval)An Interval that defines the allowable range for the y-coordinates of the box within which the points will be dilated.
height (Interval)An Interval that defines the allowable range for the z-coordinates of the box within which the points will be dilated.
origin (Point3d)The origin point from which the dilation is performed. Points are scaled outward from this location.

DilatePointsWithinCircle

#
public static void DilatePointsWithinCircle(ref Point2d[] points, int count, Point2d centre, double radius)
Spatially inflate an array of points until all but N are outside a circle.
points (ref Point2d[])Points to scale.
count (int)Number of points to retain.
centre (Point2d)Centre of circle.
radius (double)Radius of circle.

DilatePointsWithinCircle

#
public static void DilatePointsWithinCircle(ref Point3d[] points, int count, Point3d centre, double radius)
Spatially inflate an array of points until all but N are outside a circle.
points (ref Point3d[])Points to scale.
count (int)Number of points to retain.
centre (Point3d)Centre of circle.
radius (double)Radius of circle.

DilatePointsWithinRectangle

#
public static void DilatePointsWithinRectangle(ref Point2d[] points, int count, Interval width, Interval height, Point2d origin)
Spatially inflate an array of points until all but N are outside an axis aligned rectangle.
points (ref Point2d[])Points to scale.
count (int)Number of points to retain.
width (Interval)Width of axis aligned rectangle.
height (Interval)Height of axis aligned rectangle.
origin (Point2d)Scaling origin point. If the origin does not lie within the rectangle, the results cannot be trusted.

DilatePointsWithinRectangle

#
public static void DilatePointsWithinRectangle(ref Point2d[] points, int count, Interval width, Interval height)
Spatially inflate an array of points until all but N are outside an axis aligned rectangle.
points (ref Point2d[])Points to scale.
count (int)Number of points to retain.
width (Interval)Width of axis aligned rectangle.
height (Interval)Height of axis aligned rectangle.

DilatePointsWithinRectangle

#
public static void DilatePointsWithinRectangle(ref Point3d[] points, int count, Interval width, Interval height, Point3d origin)
Spatially inflate an array of points until all but N are outside an axis aligned rectangle.
points (ref Point3d[])Points to scale.
count (int)Number of points to retain.
width (Interval)Width of axis aligned rectangle.
height (Interval)Height of axis aligned rectangle.
origin (Point3d)Scaling origin point. If the origin does not lie within the rectangle, the results cannot be trusted.

DilatePointsWithinSphere

#
public static void DilatePointsWithinSphere(ref Point3d[] points, int count, Point3d centre, double radius)
Dilates a specified number of points within a defined spherical region, scaling their positions relative to a center point.
Remarks: The method performs a partial sort to efficiently determine which points are closest to the center before applying the dilation. It modifies the input array to contain only the dilated points.
points (ref Point3d[])An array of Point3d structures representing the points to be dilated. The method modifies this array to contain only the dilated points.
count (int)The number of points to retain after dilation. Must be less than or equal to the length of the points array.
centre (Point3d)The center point of the sphere around which the dilation occurs.
radius (double)The radius of the sphere within which points will be dilated. Must be a positive value.

FibonacciHalfSphere

#
public static void FibonacciHalfSphere(int count, out double[] x, out double[] y, out double[] z)
Generates the coordinates of a Fibonacci point sampling on the upper half of the unit sphere.
count (int)Number of samples.
x (out double[])Sample x coordinates.
y (out double[])Sample y coordinates.
z (out double[])Sample z coordinates.

FibonacciUnitDisc

#
public static void FibonacciUnitDisc(int count, out double[] x, out double[] y)
Generates the coordinates of a Fibonacci point sampling on the unit disc.
count (int)Number of samples.
x (out double[])Sample x coordinates.
y (out double[])Sample y coordinates.

FibonacciUnitSphere

#
public static void FibonacciUnitSphere(int count, out double[] x, out double[] y, out double[] z)
Generates the coordinates of a Fibonacci point sampling on the unit sphere.
count (int)Number of samples.
x (out double[])Sample x coordinates.
y (out double[])Sample y coordinates.
z (out double[])Sample z coordinates.

FibonacciUnitSquare

#
public static void FibonacciUnitSquare(int count, out double[] x, out double[] y)
Generates the coordinates of a Fibonacci point sampling on the unit square.
count (int)Number of samples.
x (out double[])Sample x coordinates.
y (out double[])Sample y coordinates.

FormatEngineAlgorithm

#
public static string FormatEngineAlgorithm(Engine algorithm)
Create a human-centric string which describes a certain random algorithm.
algorithm (Maths.Engine)

ParseEngineAlgorithm

#
public static bool ParseEngineAlgorithm(string text, out Engine engine)
Try and parse a random engine by name.
text (string)
engine (out Maths.Engine)

Poisson2D

#
public static Point2d[] Poisson2D(Random engine, PoissonSetup setup, Func<Point2d, double> density)
Create a two-dimensional Poisson sampling with a variable separation radius. This algorithm relies on slow spatial lookup of neighbouring coordinates since no assumptions can be made regarding the minimum allowed spacing across the entire field. As a result this method probably will not yield the same distribution as the Poisson2D method which takes a constant radius value.
engine (Random)Random engine.
setup (Maths.PseudoRandom.PoissonSetup)Properties for poisson distribution.
density (Func<Point2d, double>)Minimum allowed distance between samples. This function will be sampled and obeyed locally. It is entirely possible that a point pair exists in the final distribution closer together than one of the points local radius constraint.
An array of two-dimensional coordinates within the (min, max) region.

Poisson2D

#
public static Point2d[] Poisson2D(Random engine, PoissonSetup setup)
Create a two-dimensional Poisson sampling with a constant separation radius.
engine (Random)Random engine.
setup (Maths.PseudoRandom.PoissonSetup)Properties for poisson distribution.
An array of two-dimensional coordinates within the (min, max) region, no two of which are closer than the specified radius.

Populate1D

#
public static double[] Populate1D(Random engine, double min, double max, int count, double spread)
Randomly populate a one-dimensional interval. This method works by randomly dividing the longest remaining interval into two until a fixed number of values has been found.
engine (Random)Random engine to use.
min (double)Lower limit.
max (double)Upper limit.
count (int)Number of values to create.
spread (double)Spreading factor (0, 1). Zero equals splitting exactly in the middle, one equals splitting within the full domain.
An array of numbers between min and max.

RandomIntegers

#
public static IEnumerable<int> RandomIntegers(Engine engine, int seed, int lowerInclusive, int upperExclusive)
Generate an enumeration of random, non-negative integers.
engine (Maths.Engine)Engine to use.
seed (int)Initial seed value.
lowerInclusive (int)Lower inclusive limit.
upperExclusive (int)Upper exclusive limit.
Infinite collection of random integers.

RandomIntegers

#
public static IEnumerable<int> RandomIntegers(Engine engine, int seed)
Generate an enumeration of random, non-negative integers.
engine (Maths.Engine)Engine to use.
seed (int)Initial seed value.
Infinite collection of random integers.

RandomIntegers

#
public static int[] RandomIntegers(Engine engine, int seed, int count, int lowerInclusive, int upperExclusive)
Generate an enumeration of random, non-negative integers.
engine (Maths.Engine)Engine to use.
seed (int)Initial seed value.
count (int)Amount of random numbers to generate.
lowerInclusive (int)Lower inclusive limit.
upperExclusive (int)Upper exclusive limit.
Infinite collection of random integers.

RandomIntegers

#
public static int[] RandomIntegers(Engine engine, int seed, int count)
Generate an enumeration of random, non-negative integers.
engine (Maths.Engine)Engine to use.
seed (int)Initial seed value.
count (int)Amount of random numbers to generate.
Infinite collection of random integers.

RandomNumbers

#
public static double[] RandomNumbers(Engine engine, int seed, int count, double lower, double upper)
Generate an enumeration of random, non-negative integers.
engine (Maths.Engine)Engine to use.
seed (int)Initial seed value.
count (int)Amount of random numbers to generate.
lower (double)Lower limit.
upper (double)Upper limit.
Infinite collection of random integers.

RandomNumbers

#
public static double[] RandomNumbers(Engine engine, int seed, int count)
Generate an enumeration of random, non-negative integers.
engine (Maths.Engine)Engine to use.
seed (int)Initial seed value.
count (int)Amount of random numbers to generate.
Infinite collection of random integers.

RandomNumbers

#
public static IEnumerable<double> RandomNumbers(Engine engine, int seed, double lower, double upper)
Generate an enumeration of random, non-negative integers.
engine (Maths.Engine)Engine to use.
seed (int)Initial seed value.
lower (double)Lower limit.
upper (double)Upper limit.
Infinite collection of random integers.

RandomNumbers

#
public static IEnumerable<double> RandomNumbers(Engine engine, int seed)
Generate an enumeration of random, non-negative integers.
engine (Maths.Engine)Engine to use.
seed (int)Initial seed value.
Infinite collection of random integers.

VanDerCorputUnitCube

#
public static void VanDerCorputUnitCube(int count, out double[] x, out double[] y, out double[] z)
Create a Van Der Corput distribution within the unit cube.
count (int)
x (out double[])
y (out double[])
z (out double[])

VanDerCorputUnitSquare

#
public static void VanDerCorputUnitSquare(int count, out double[] x, out double[] y)
Generates the coordinates of a van der Corput Quasi random point set on the unit square. The distances between adjacent points are more similar than using a strict pseudo-random distribution, not quite as good as a Poisson distribution but very fast. The x coordinates increase steadily from zero to (n-1)/n, whereas the associated y coordinates are spread out using a quasi-mote-carlo pattern.
count (int)Number of points.
x (out double[])X coordinates of random points.
y (out double[])Y coordinates of random points.