Last active
July 18, 2016 13:29
-
-
Save mattebb/2c11f7e4f15ea20d5483 to your computer and use it in GitHub Desktop.
Weighted random VEX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int i, steps = 80; | |
float sumhist[], sum=0, slice = 1.0/float(steps); | |
seed += 123456789; | |
for (i=0;i<steps;i++) { | |
float pos = (i*slice); | |
float val = chramp("__rndweight", pos); | |
sum += val; | |
push(sumhist, sum); | |
} | |
float rnd = random(seed) * sum; | |
// linear search | |
for(i=0;i<steps-1;i++) { | |
if (rnd > sumhist[i] && rnd <= sumhist[i+1]) | |
break; | |
} | |
weight_random = float(i)/float(steps) + random(seed+123)*slice; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment