I'm attempting to create a way to intuitively weight how I randomly distribute assets via copy to points as well as what shaders are assigned via redshift's shader switch. I was able to successfully get this all to work with the standard rand() function but quickly realized the even distribution wasn't going to work for me. What I was able to come up with so far seems to work at first but if the values are close to equally weighted it begins to fall apart. My math is not the strongest which is why I have every variable output as an attribute to check what it's doing but I'm currently at a loss as to how to go about doing this.
Here's what i'm putting into my wrangle :
f@choiceA = chf(“A_Probability”);
f@choiceB = chf(“B_Probability”);
f@choiceC = chf(“C_Probability”);
f@max = @choiceA + @choiceB + @choiceC;
f@choiceA_percent = @choiceA / @max;
f@choiceB_percent = @choiceB / @max;
f@choiceC_percent = @choiceC / @max;
int seed = 2456;
f@randomNumber = rand(@ptnum + seed);
i@choice = 0;
if(@randomNumber < @choiceA_percent){
@choice = 0;
}
if(@randomNumber < @choiceB_percent){
@choice = 1;
}
if(@randomNumber < @choiceC_percent){
@choice = 2;
}
Weighting Random Values / Probability Distribution in VEX
6397 4 0-
- drossxyu
- Member
- 31 posts
- Joined: July 2015
- Offline
-
- Aizatulin
- Member
- 502 posts
- Joined: July 2005
- Online
Hi,
you are on the right way, but one thing is missing.
If you want to handle all the weights in an equal way, you have to accumulate them. A way to do this, is storing them into an array and normalize them (1 should me max).
You'll get something like this: (0.1, 0.25, 0.6, 1.0).
If you generate a random number, it will be between 0 and 1.
For example if the random number is 0.05, the index will be 0,
and if the random number is 0.5, the index is 2.
Here is an example.
you are on the right way, but one thing is missing.
If you want to handle all the weights in an equal way, you have to accumulate them. A way to do this, is storing them into an array and normalize them (1 should me max).
You'll get something like this: (0.1, 0.25, 0.6, 1.0).
If you generate a random number, it will be between 0 and 1.
For example if the random number is 0.05, the index will be 0,
and if the random number is 0.5, the index is 2.
Here is an example.
Edited by Aizatulin - June 30, 2019 02:18:54
-
- drossxyu
- Member
- 31 posts
- Joined: July 2015
- Offline
-
- tamte
- Member
- 9249 posts
- Joined: July 2007
- Offline
-
- Aizatulin
- Member
- 502 posts
- Joined: July 2005
- Online
-
- Quick Links