Quick Start Guide
Eidolon.Random
is a comprehensive Unity package designed to elevate your game development experience by providing a robust suite of randomization utilities. Whether you need to generate random numbers, colors, vectors, rotations, or even simulate normal distributions, this package has you covered.
1. Generate Random Boolean:
RandomBool
method returns a random boolean value with an optional probability of being true. By default, the probability is set to 0.5, providing a simple way to introduce randomness.
// Generate a random boolean with default probabilitybool randomResult = RandomUtil.RandomBool();
2. Generate Random Integer:
RandomNumber
method returns a random integer between the specified range (inclusive on the min and exclusive on the max), allowing for diverse random number generation.
// Generate a random integer between 1 (inclusive) and 10 (exclusive)int randomNumber = RandomUtil.RandomNumber(1, 10);
3. Select Random Element from Array:
RandomElement
method picks a random element from an array, providing flexibility in selecting random items from a predefined list.
// Example array of colorsColor[] colorArray = new Color[]{ new Color(1.0f, 0.0f, 0.0f, 1.0f), // Red new Color(0.0f, 1.0f, 0.0f, 1.0f), // Green new Color(0.0f, 0.0f, 1.0f, 1.0f), // Blue new Color(1.0f, 1.0f, 0.0f, 1.0f), // Yellow};
// Select a random element from an array of colorsColor randomColor = RandomUtil.RandomElement(colorArray);
4. Generate Random Color:
RandomColor
method generates a random color, offering a quick way to introduce variety in color selection.
// Generate a random colorColor randomColor = RandomUtil.RandomColor();
5. Generate Random 3D Vector:
RandomVector3D
method returns a random 3D vector within specified ranges, facilitating the creation of diverse spatial positions.
// Generate a random 3D vector within specified rangesVector3 randomVector3D = RandomUtil.RandomVector3D(new Vector3(0, 0, 0), new Vector3(10, 10, 10));
6. Generate Random 2D Vector:
RandomVector2D
method generates a random 2D vector within specified ranges, useful for 2D game development.
// Generate a random 2D vector within specified rangesVector2 randomVector2D = RandomUtil.RandomVector2D(new Vector2(0, 0), new Vector2(5, 5));
7. Generate Random Rotation:
RandomRotation
method returns a random rotation, allowing for random orientation adjustments. This can be used in either 2D or 3D games.
// Generate a random 2D rotationQuaternion randomRotation2D = RandomUtil.RandomRotation2D();
// Generate a random 3D rotationQuaternion randomRotation3D = RandomUtil.RandomRotation3D();
8. Generate Random Angle in Radians:
RandomAngle
method returns a random angle in radians, providing a flexible way to introduce random angular values.
// Generate a random angle in radiansfloat randomRadians = RandomUtil.RandomAngle();
9. Generate Random 2D Vector on Unit Circle:
RandomOnUnitCircle
method returns a random 2D vector on the unit circle, useful for directional randomness.
// Generate a random 2D vector on the unit circleVector2 randomUnitVector = RandomUtil.RandomOnUnitCircle();
10. Generate Random Value from Normal Distribution:
RandomNormalDistribution
method returns a random value from a normal distribution with specified mean and standard deviation.
// Generate a random value from a normal distributionfloat randomNormalValue = RandomUtil.RandomNormalDistribution(0, 1);
11. Select Random Audio Clip from Array:
RandomAudioClip
method selects a random audio clip from an array, enhancing audio variety in your project.
// Example array of audio clipsAudioClip[] audioClips = { audioClip1, audioClip2, audioClip3, audioClip4 };
// Select a random audio clip from an array of sound effectsAudioClip randomAudioClip = RandomUtil.RandomAudioClip(audioClips);
12. Select Random Element from List:
RandomElement
method selects a random element from a generic list, offering flexibility in managing dynamic collections.
// Example list of colorsList<Color> colorList = new List<Color>{ new Color(1.0f, 0.0f, 0.0f, 1.0f), // Red new Color(0.0f, 1.0f, 0.0f, 1.0f), // Green new Color(0.0f, 0.0f, 1.0f, 1.0f), // Blue new Color(1.0f, 1.0f, 0.0f, 1.0f), // Yellow};
// Select a random element from a list of colorsColor randomColor = RandomUtil.RandomElement(colorList);
13. Generate Random Float:
RandomFloat
method returns a random float between the specified range (inclusive on the min and exclusive on the max), allowing for diverse random float generation.
// Generate a random float between 1 (inclusive) and 10 (exclusive)int randomNumber = RandomUtil.RandomFloat(1, 10);
Feel free to integrate these methods into your Unity project for versatile and controlled randomness!