Description
The Gaussian2D
method is an extension method for the System.Random
class, which generates a random 2D vector following a Gaussian (normal) distribution. This method allows you to specify the mean and standard deviation for each component of the vector, providing flexibility in generating random vectors that fit specific statistical properties.
Usage
To use the Gaussian2D
method, you need to have an instance of System.Random
. You can then call this method to generate a random Vector2
with the desired mean and standard deviation. If the mean or standard deviation is not specified, the method will use default values.
Parameters:
self
: The System.Random
instance used to generate random numbers.
mean
: An optional Vector2
specifying the mean of the distribution. If not provided, a default mean of (0, 0) is used.
stdDev
: An optional Vector2
specifying the standard deviation of the distribution. If not provided, a default standard deviation of (1, 1) is used.
Example
// Example usage of Gaussian2D
System.Random random = new System.Random();
Vector2 mean = new Vector2(5.0f, 10.0f);
Vector2 stdDev = new Vector2(2.0f, 3.0f);
// Generate a random Vector2 with specified mean and standard deviation
Vector2 randomVector = random.Gaussian2D(mean, stdDev);
// Output the generated vector
// Note: Replace with appropriate logging or handling in your application
// e.g., Debug.Log(randomVector);