Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: djaydino on October 02, 2014, 08:52:41 AM
-
hi,
i like to know more about how the random weight works
for example i have 2 random events, both set to 1.0, this is a 50/50% right?
but when it is set to 0.9 and 0.1 is it 90% / 10% then?
when i have 3 items. set like this 1.0 / 0.8 / 0.8 how does the chance % work then?
basically i would like to know how this calculates.
-
does it work like this ?
1.0 + 0.8 + .08 = 2.6 and the random fall inside this given number .
item 1 : 1.0 chance out of 2.6
item 2 : 0.8 chance out of 2.6
item 3 : 0.8 chance out of 2.6
-
anyone knows how this works?
-
Hi,
I don't know to be honest. I think it that if you have two values weighted at 0.1 and the other at 0.9, then it's 90% of chance and 10% of chance to get them. that is if the sum of the weights are 100.
Bye,
Jean
-
Has anyone figured out the dark magic behind.weighted values? I still can't grasp the concept.
-
Hi.
This is the code of the weighted :
/// <summary>
/// Given an array of weights, returns a randomly selected index.
/// </summary>
public static int GetRandomWeightedIndex(FsmFloat[] weights)
{
float totalWeight = 0;
foreach (var t in weights)
{
totalWeight += t.Value;
}
var random = Random.Range(0, totalWeight);
for (var i = 0; i < weights.Length; i++)
{
if (random < weights[i].Value)
{
return i;
}
random -= weights[i].Value;
}
return -1;
}