Miscellaneous scripts
This repository contains miscellaneous scripts that does not fit in one repository, yet I will use them sometimes for my personal use. Note that some of the scripts might contain hardcoded paths and opinionated presets, and you are advised to inspect them before actually using.
Loading...
Searching...
No Matches
empiricially.c File Reference
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
Include dependency graph for empiricially.c:

Go to the source code of this file.

Functions

int main ()
int randint (int n)

Function Documentation

◆ main()

int main ( void )

Definition at line 34 of file empiricially.c.

34 {
35 int a,b,c=0;
36 srand((unsigned int) time(NULL));
37 for (int d = 0; d<1000000; d++)
38 {
39 if (a==4) {b++;}
40 else
41 {
42 if (b==3) {a++;}
43 else {
44 if (randint(2)==1) {a++;}
45 else {b++;}
46 }
47 }
48 if ((a==4) && (b==2))
49 {
50 c++;
51 a=0;
52 b=0;
53 }
54 if ((a==4) && (b==3))
55 {
56 a=0;
57 b=0;
58 }
59 }
60 printf("%d", 1000000 / c);
61 return 0;
62}
int randint(int n)

References randint().

Here is the call graph for this function:

◆ randint()

int randint ( int n)

Definition at line 11 of file empiricially.c.

11 {
12 if ((n - 1) == RAND_MAX) {
13 return rand();
14 } else {
15 // Supporting larger values for n would requires an even more
16 // elaborate implementation that combines multiple calls to rand()
17 assert (n <= RAND_MAX);
18
19 // Chop off all of the values that would cause skew...
20 int end = RAND_MAX / n; // truncate skew
21 assert (end > 0);
22 end *= n;
23
24 // ... and ignore results from rand() that fall above that limit.
25 // (Worst case the loop condition should succeed 50% of the time,
26 // so we can expect to bail out of this loop pretty quickly.)
27 int r;
28 while ((r = rand()) >= end);
29
30 return r % n;
31 }
32}

Referenced by main().

Here is the caller graph for this function: