#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdlib.h>
#include <stdio.h>

int randcount;

__attribute__((constructor)) void library_init() {
    printf("Initializing Library\n");
    randcount = 0;
}

__attribute__((destructor)) void library_done() {
    printf("Library is about to be unloaded. rc = %d\n", randcount);
}



int (*original_rand)(void) = NULL;

int rand() {
    randcount++;
    if (original_rand == NULL) {
        original_rand = dlsym(RTLD_NEXT, "rand");
    }
    return original_rand() % 100;
}


