You will need to create a global array with all elements explicitly initialized. Elements must be randomized, otherwise the compiler will probably optimize the list of initializers in the compiled code.
First you need a separate program to generate your array:
#include <stdio.h> #include <stdlib.h> #include <unistd.h> int main() { int len = 100000000; int i; srand(getpid()); printf("unsigned char buf[%d] = {\n", len); for (i=0;i<len;i++) { printf(" %hhu,", rand() & 0xff); if (i%16==15) printf("\n"); } printf("};\n\n"); return 0; }
Run this and redirect the output to a file:
./array_generator > array.c
Then you get a .c array that looks something like this:
unsigned char buf[1000000] = { 247, 223, 30, 51, 46, 247, 133, 136, 254, 225, 82, 135, 68, 176, 240, 7, 29, 245, 104, 203, 230, 83, 127, 189, 37, 5, 168, 105, 134, 9, 229, 125, 232, 3, 176, 23, 251, 53, 159, 249, 22, 241, 128, 90, 161, 112, 97, 191, 101, 202, 138, 75, 29, 10, 9, 66, 15, 177, 171, 149, 186, 145, 18, 163, ... };
Then you include this in your main source:
#include "array.c"