forked from personal/squiggle.c
46 lines
1.3 KiB
C
46 lines
1.3 KiB
C
#include "../squiggle.h"
|
|
#include "../squiggle_more.h"
|
|
#include <math.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
int main()
|
|
{
|
|
// Replicate <https://arxiv.org/pdf/1806.02404.pdf>, and in particular the red line in page 11.
|
|
// Could also be interesting to just produce and save many samples.
|
|
|
|
// set randomness seed
|
|
uint64_t* seed = malloc(sizeof(uint64_t));
|
|
*seed = UINT64_MAX/64; // xorshift can't start with a seed of 0
|
|
|
|
int n_samples = 100*MILLION;
|
|
int p_sixteenth = 0;
|
|
int p_eighth = 0;
|
|
int p_quarter = 0;
|
|
int p_half = 0;
|
|
double sample;
|
|
for(int i=0; i<n_samples; i++){
|
|
sample = sample_unit_uniform(seed);
|
|
// printf("%lf\n", sample);
|
|
if (sample < 1.0/16.0){
|
|
p_sixteenth++;
|
|
p_eighth++;
|
|
p_quarter++;
|
|
p_half++;
|
|
} else if(sample < 0.125){
|
|
p_eighth++;
|
|
p_quarter++;
|
|
p_half++;
|
|
} else if(sample < 0.25){
|
|
p_quarter++;
|
|
p_half++;
|
|
} else if(sample < 0.5){
|
|
p_half++;
|
|
}else{
|
|
// printf("Sample > 0.5\n");
|
|
}
|
|
}
|
|
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);
|
|
}
|