Skip to content

Instantly share code, notes, and snippets.

@guidanoli
Created August 28, 2019 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guidanoli/c72e186e8e928ce00562510ec9baedd9 to your computer and use it in GitHub Desktop.
Save guidanoli/c72e186e8e928ce00562510ec9baedd9 to your computer and use it in GitHub Desktop.
Bernoulli distribution simulation
/*
* 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