fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. unsigned int seed = 0xfdb462a7U;
  5. unsigned int rng()
  6. {
  7. seed *= 0x41c64e6dU;
  8. const unsigned int truncated = ((seed + 0x303aU) >> 16) & 0xff;
  9. seed += 0x3039U;
  10. return truncated & 0xff;
  11. }
  12.  
  13. unsigned int convert(unsigned int value)
  14. {
  15. unsigned int product = ((unsigned long long)value * (unsigned long long)0xcccccccdU) >> 32;
  16. unsigned int shifted = (product >> 3);
  17. return (shifted + (shifted << 2)) << 1;
  18. }
  19.  
  20. int main()
  21. {
  22. const unsigned int generated = rng();
  23. cout << hex << "Random number: " << generated << endl;
  24. cout << hex << "Final dice roll value: " << (generated - convert(generated)) + 1 << endl;
  25.  
  26. cout << "Division:" << endl;
  27. unsigned int end;
  28. for (unsigned int start = 0; start <= 255; start = end)
  29. {
  30. unsigned int startValue = convert(start);
  31. for (end = start + 1; end <= 255; ++end)
  32. {
  33. unsigned int endValue = convert(end);
  34. if (startValue != endValue)
  35. {
  36. break;
  37. }
  38. }
  39. cout << dec << "[" << start << ", " << (end - 1) << "] maps to " << startValue << endl;
  40. }
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 5392KB
stdin
Standard input is empty
stdout
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