Skip to content

Instantly share code, notes, and snippets.

@ryanmjacobs
Created November 20, 2016 08:31
Show Gist options
  • Save ryanmjacobs/d66510ce160d0e9f4ec29d99c50ae3d1 to your computer and use it in GitHub Desktop.
Save ryanmjacobs/d66510ce160d0e9f4ec29d99c50ae3d1 to your computer and use it in GitHub Desktop.
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#define NUM_TRIALS 1e9
int randint(int n);
unsigned int play(void);
int main(void) {
srand(time(NULL));
unsigned long long int total = 0;
for (int i = 0; i < NUM_TRIALS; i++) {
total += play();
}
printf("average win: %0.2f\n", total/NUM_TRIALS);
return 0;
}
unsigned int play(void) {
unsigned int pot = 1;
while (rand() % 2 == 0)
pot *= 2;
return pot;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment