#include #include int main(int argc, char **argv) { int table[1000]; bool covered[256]; for(int table_size = 256; table_size < static_cast(sizeof(table) / sizeof(table[0])); table_size++) { // Populate table with linear congruential generator for(int multiplier = 2; multiplier < 10; multiplier++) { for(int i = 0; i < table_size; i++) table[i] = -1; int x = 0; int cycle_length = 0; for(;;) { const int y = -~x * multiplier % table_size; if( table[y] >= 0 ) break; table[y] = x; x = y; cycle_length++; } // Check if differences between table cells is sufficient to encode // all byte values. bool usable = true; for(int x = 0; x < table_size && usable; x++) { if( table[x] < 0 ) continue; for(int i = 0; i < 256; i++) covered[i] = false; int cover_count = 0; int y = x; for(int step_count = 0; step_count < table_size; step_count++) { y = table[y]; const int diff = abs(y - x); if( diff < 256 && !covered[diff] ) { cover_count++; covered[diff] = true; } if( y == x ) break; } if( cover_count < 256 ) { usable = false; break; } } if( usable ) { printf("table_size = %d, cycle_length = %d, multiplier = %d\n", table_size, cycle_length, multiplier); } } } return 0; }