A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/tucano/UnityRandom below:

tucano/UnityRandom: Random library in C# for Unity3D

Random Numbers for Unity3d

Homepage: http://tucanosoftware.com/projects/unityrandom

Example: http://108.166.95.149/UnityTest/UnityRandomExample/UnityRandomExample.html

In Unity3d there is already a Random number generator based on the platform-specific random generator.
Here we present an alternative Random library for Unity3d designed to generate uniform Pseudo-Random deviates.
The library use a fast PRNG (Mersenne-Twister) to generate: Floating Numbers in range [0-1] and in range [n-m], Vector2 and Vector3 data types.
The library comes with some special functions designed specifically for a game design framework: Shuffle Bag, Dice, Random Color.

Which kind of transformations I can apply to the random uniform deviates?

The uniform deviates can be transformed with the distributions: Standard Normal Distribution and Power-Law. In addition is possible to generate floating random deviates coming from other distributions: Poisson, Exponential and Gamma.

How I can test the random numbers?

The library add a window to the Unity3D editor that allow you to Test and Visualize your random numbers, Vector2 and Vector3. With the SAVE button, you can write the sample of random number to a txt file. This is useful if you need to analyze in deep the distribution of your random numbers with a statistical software.

Initialization
Initialization with a seed: UnityRandom urand = new UnityRandom(int seed);

Numbers
A Random number in range [0-1]: @float val = urand.Value()

Transformations
A Random number in range [0-1] with a Transformation: float val = urand.Value(UnityRandom.Normalization.STDNORMAL, 5.0f)

Vectors
A random point in a disk with R=1: Vector2 pos = urand.PointInADisk()

Colors
A random color in the range of visible light (rainbow): Color col = urand.Rainbow()

Dice
A 2D6 dice roll DiceRoll roll = urand.RollDice(2,DiceRoll.DiceType.D6)

Shuffle Bag

In games or educational programs you often don’t want real randomness. Unsurprisingly random it’s often a bit too random. You may get some items several times in a row and others too rarely. It’s either too easy or too hard. Balancing the weights is hard as well, because each run is too different. And if that wouldn’t be already bad enough; it’s also difficult to verify the results.

A shuffle Bag with values: [1,10]

float[] shufflebag = {1,2,3,4,5,6,7,8,9,10};

ShuffleBagCollection<float> thebag = _urand.ShuffleBag(shufflebag);

float randvalue = thebag.Next()

A shuffle bag with weighted values:

Dictionary wshufflebag = new Dictionary<float,int>();

wshufflebag[1] = 5;

wshufflebag[2] = 45;

wshufflebag[3] = 25;

wshufflebag[4] = 25;

@ShuffleBagCollection thebag = _urand.ShuffleBag(wshufflebag); @

float randvalue = thebag.Next()

Generation of uniform deviates in any range.

Available Transformations

generation of Unity Vector2 Objects.

generation of Unity Vector3

Dice types:

Example 2D6:

DiceRoll roll = urand.RollDice(2,DiceRoll.DiceType.D6)

From: http://kaioa.com/node/53

In games or educational programs you often don’t want real randomness. Unsurprisingly random it’s often a bit too random. You may get some items several times in a row and others too rarely. It’s either too easy or too hard. Balancing the weights is hard as well, because each run is too different. And if that wouldn’t be already bad enough; it’s also difficult to verify the results.

A shuffle Bag with values: [1,10]

float[] shufflebag = {1,2,3,4,5,6,7,8,9,10};

ShuffleBagCollection<float> thebag = _urand.ShuffleBag(shufflebag);

float randvalue = thebag.Next()

A shuffle bag with weighted values:

Dictionary wshufflebag = new Dictionary<float,int>();

wshufflebag[1] = 5;

wshufflebag[2] = 45;

wshufflebag[3] = 25;

wshufflebag[4] = 25;

@ShuffleBagCollection thebag = _urand.ShuffleBag(wshufflebag); @

float randvalue = thebag.Next()


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4