not reading binary file correctly. giving me random values. 


#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <unistd.h>

#define MESSAGE "%ld reads were done in %ld seconds.\n"

long num_reads, seconds;

int main(int argc, char **argv) {
    if (argc != 3) {
        fprintf(stderr, "Usage: time_reads s filename\n");
        exit(1);
    }
    seconds = strtol(argv[1], NULL, 10);

    FILE *fp;
    if ((fp = fopen(argv[2], "r")) == NULL) {
        perror("fopen");
        exit(1);
    }

    int rand_idx;
    int value_at_idx;
    for (int i = 0; i < 100; i++) {
        rand_idx = (int)(((double)random() / RAND_MAX) * 99);
        fseek(fp, rand_idx, SEEK_SET);
        fread(&value_at_idx, sizeof(int), 1, fp);
        printf("%i\n", value_at_idx);
    }
    return 1;
}
