Created
August 28, 2019 12:44
-
-
Save guidanoli/c72e186e8e928ce00562510ec9baedd9 to your computer and use it in GitHub Desktop.
Bernoulli distribution simulation
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
/* | |
* bernoulli.c | |
* | |
* Bernoulli distribution simulation | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <assert.h> | |
int main(int argc, char ** argv) | |
{ | |
double p; | |
assert(argc == 2); | |
assert(sscanf(argv[1], "%lf", &p) == 1); | |
assert(p != 0); | |
srand (time(NULL)); | |
double r = (double) rand() / (double) RAND_MAX; | |
if (r <= 1 - p) | |
puts("HEADS"); | |
else | |
puts("TAILS"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment