Random Number Generator (RNG) is a crucial component of online casino games and many other digital applications that require randomness. An RNG is a software algorithm designed to generate a sequence of numbers or outcomes that appear to be random and unpredictable.
For get any random value, you can use any of this methods
var random = await _fireball.Random.GetRandomInt(minInt, maxInt);
var random = await _fireball.Random.GetRandomDouble(minDouble, maxDouble);
var random = await _fireball.Random.GetRandomBool();
Additionally, you can randomly shuffle any list by using:
// create list of any type
var list = new List<string>()
{
"one", "two", "three"
};
// number of shuffle iterations
int iterations = 5;
// randomlly shuffle list
await _fireball.Random.Shuffle(list, iterations);
or get random element index from weighted array:
public class ElementData
{
public string Id;
public float Chance;
public ElementData(string id, float chance)
{
Id = id;
Chance = chance;
}
}
....
// game data object example
var elements = new List<ElementData>()
{
new ElementData("ace", 0.1f ),
new ElementData("king", 0.2f ),
new ElementData("queen", 0.3f ),
new ElementData("jack", 0.4f ),
};
// select weights list from game data
var weigths = elements.Select(w => (double)w.Chance).ToList();
// randomlly select weghted element from list
int index = await _fireball.Random.GetRandomIndexFromWeightsArray(weigths);
// result
var random = elements[index];