squiggle.c

Self-contained Monte Carlo estimation in C99
Log | Files | Refs | README

example.c (597B)


      1 #include "../../../squiggle.h"
      2 #include "../../../squiggle_more.h"
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 
      6 int main()
      7 {
      8     // set randomness seed
      9     uint64_t* seed = malloc(sizeof(uint64_t));
     10     *seed = 1000; // xorshift can't start with a seed of 0
     11 
     12     int n = 1000000;
     13     double* xs = malloc(sizeof(double) * (size_t)n);
     14     for (int i = 0; i < n; i++) {
     15         xs[i] = sample_to(10, 100, seed);
     16     }
     17     ci ci_90 = array_get_90_ci(xs, n);
     18     printf("Recovering confidence interval of sample_to(10, 100):\n  low: %f, high: %f\n", ci_90.low, ci_90.high);
     19 
     20     free(xs);
     21     free(seed);
     22 }