Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. r = a + binary2dec(flip n times write 0 for heads and 1 for tails)
  2.  
  3. n = b-a;
  4. N = round_to_next_larger_power_of_2(n)
  5. while (1) {
  6. x = random(0 included to N excluded);
  7. if (x < n) break;
  8. }
  9. r = a + x;
  10.  
  11. public static IEnumerable<BigInteger> DigitConversion(this IEnumerable<BigInteger> inputStream, BigInteger modIn, BigInteger modOut) {
  12. //note: values are implicitly scaled so the first unfixed digit of the output ranges from 0 to 1
  13. Rational b = 0; //offset of the chosen range
  14. Rational d = 1; //size of the chosen range
  15. foreach (var r in inputStream) {
  16. //narrow the chosen range towards the real value represented by the input
  17. d /= modIn;
  18. b += d * r;
  19. //check for output digits that have become fixed
  20. while (true) {
  21. var i1 = (b * modOut).Floor();
  22. var i2 = ((b + d) * modOut).Floor(); //note: ideally b+d-epsilon, but another iteration makes that correction unnecessary
  23. if (i1 != i2) break; //digit became fixed?
  24. //fix the next output digit (rescale the range to make next digit range from 0 to 1)
  25. d *= modOut;
  26. b *= modOut;
  27. b -= i1;
  28. yield return i1;
  29. }
  30. }
  31. }
  32.  
  33. Keep a random seed s and initialize with s = R(m).
  34.  
  35. function random [0, z-1] :
  36. x = R(m) + s
  37. while x >= z:
  38. x -= z
  39. s = x
  40. return x
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement