fork(3) download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3.  
  4. #define LOW(exp) ((exp) & 0x00FF)
  5. #define HIGH(exp) (((exp) & 0xFF00) >> 8)
  6.  
  7.  
  8. uint16_t prng(uint16_t v) {
  9.  
  10. uint16_t low = LOW(v);
  11. uint16_t high = HIGH(v);
  12.  
  13. uint16_t mul_low = low * 5;
  14. uint16_t mul_high = high * 5;
  15.  
  16. // need to check for overflow, since final addition is adc as well
  17. uint16_t v1 = LOW(mul_high) + HIGH(mul_low) + 1;
  18. uint8_t carry = HIGH(v1) & 0b00000001;
  19.  
  20. uint16_t v2 = (LOW(v1) << 8) + LOW(mul_low);
  21.  
  22. return (v2 + 0b00010001 + carry);
  23. }
  24.  
  25. int main()
  26. {
  27. printf("%d\n", prng(13054));
  28. printf("%d\n", prng(13055));
  29. printf("%d\n", prng(13056));
  30. printf("%d\n", prng(13057));
  31.  
  32. printf("---\n");
  33.  
  34. printf("%d\n", prng(13310));
  35. printf("%d\n", prng(13311));
  36. printf("%d\n", prng(13312));
  37. printf("%d\n", prng(13313));
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 2160KB
stdin
Standard input is empty
stdout
7
12
18
23
---
1288
1293
1297
1302