Last active
March 31, 2017 02:46
-
-
Save qiuwch/7d5845d768366ae7a4e7 to your computer and use it in GitHub Desktop.
Sample a value from a distribution #tags: algorithm
This file contains hidden or 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
| 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