scratchpad.c (1357B)
1 #include "../squiggle.h" 2 #include "../squiggle_more.h" 3 #include <math.h> 4 #include <stdint.h> 5 #include <stdio.h> 6 #include <stdlib.h> 7 8 int main() 9 { 10 // Replicate <https://arxiv.org/pdf/1806.02404.pdf>, and in particular the red line in page 11. 11 // Could also be interesting to just produce and save many samples. 12 13 // set randomness seed 14 uint64_t* seed = malloc(sizeof(uint64_t)); 15 *seed = UINT64_MAX/64; // xorshift can't start with a seed of 0 16 17 int n_samples = 100*MILLION; 18 int p_sixteenth = 0; 19 int p_eighth = 0; 20 int p_quarter = 0; 21 int p_half = 0; 22 double sample; 23 for(int i=0; i<n_samples; i++){ 24 sample = sample_unit_uniform(seed); 25 // printf("%lf\n", sample); 26 if (sample < 1.0/16.0){ 27 p_sixteenth++; 28 p_eighth++; 29 p_quarter++; 30 p_half++; 31 } else if(sample < 0.125){ 32 p_eighth++; 33 p_quarter++; 34 p_half++; 35 } else if(sample < 0.25){ 36 p_quarter++; 37 p_half++; 38 } else if(sample < 0.5){ 39 p_half++; 40 }else{ 41 // printf("Sample > 0.5\n"); 42 } 43 } 44 printf("p_16th: %lf; p_eighth; %lf; p_quarter: %lf; p_half: %lf", ((double)p_sixteenth)/n_samples, (double)p_eighth/n_samples, (double)p_quarter/n_samples, (double)p_half/n_samples); 45 }