#include
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;
}