#include <iostream> using namespace std; unsigned int seed = 0xfdb462a7U; unsigned int rng() { seed *= 0x41c64e6dU; const unsigned int truncated = ((seed + 0x303aU) >> 16) & 0xff; seed += 0x3039U; return truncated & 0xff; } unsigned int convert(unsigned int value) { unsigned int product = ((unsigned long long)value * (unsigned long long)0xcccccccdU) >> 32; unsigned int shifted = (product >> 3); return (shifted + (shifted << 2)) << 1; } int main() { const unsigned int generated = rng(); cout << hex << "Random number: " << generated << endl; cout << hex << "Final dice roll value: " << (generated - convert(generated)) + 1 << endl; cout << "Division:" << endl; unsigned int end; for (unsigned int start = 0; start <= 255; start = end) { unsigned int startValue = convert(start); for (end = start + 1; end <= 255; ++end) { unsigned int endValue = convert(end); if (startValue != endValue) { break; } } cout << dec << "[" << start << ", " << (end - 1) << "] maps to " << startValue << endl; } return 0; }
Standard input is empty
Random number: 7 Final dice roll value: 8 Division: [0, 9] maps to 0 [10, 19] maps to 10 [20, 29] maps to 20 [30, 39] maps to 30 [40, 49] maps to 40 [50, 59] maps to 50 [60, 69] maps to 60 [70, 79] maps to 70 [80, 89] maps to 80 [90, 99] maps to 90 [100, 109] maps to 100 [110, 119] maps to 110 [120, 129] maps to 120 [130, 139] maps to 130 [140, 149] maps to 140 [150, 159] maps to 150 [160, 169] maps to 160 [170, 179] maps to 170 [180, 189] maps to 180 [190, 199] maps to 190 [200, 209] maps to 200 [210, 219] maps to 210 [220, 229] maps to 220 [230, 239] maps to 230 [240, 249] maps to 240 [250, 255] maps to 250