Skip to content

Instantly share code, notes, and snippets.

@qiuwch
Last active March 31, 2017 02:46
Show Gist options
  • Select an option

  • Save qiuwch/7d5845d768366ae7a4e7 to your computer and use it in GitHub Desktop.

Select an option

Save qiuwch/7d5845d768366ae7a4e7 to your computer and use it in GitHub Desktop.
Sample a value from a distribution #tags: algorithm
double random_num = (double)rand() / RAND_MAX;
for (k = 0; k <= MAX_INTENSITY; k++)
{
if (random_num < probs[k])
{
synthesized[i*im_width+j] = k; // update synthesized image
break;
}
else
random_num = random_num - probs[k];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment