Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Oh, you're so random

Oh, you're so random

Randomness and pink ponies in Codemotion Rome 2012

6804f1775cb4babfcc3851298566fbce?s=128

Vicent Martí

March 25, 2012
Tweet

Transcript

  1. None
  2. select a random element

  3. select a random element ‘tis one is ok.

  4. None
  5. None
  6. Information Theory

  7. hard TOPIC Information Theory

  8. hard TOPIC dumb SPEAKER + Information Theory

  9. 0≤H(X)≤1 where X is a discrete random variable

  10. 0≤H(X)≤1 where X is a discrete random variable unpredictable

  11. 0≤H(X)≤1 where X is a discrete random variable unpredictable always

    the same
  12. None
  13. ask a question.

  14. None
  15. bool is_random(char *bytes, size_t n) { }

  16. bool is_random(char *bytes, size_t n) { } AGHHH

  17. UNIFORM distribution

  18. UNIFORM distribution

  19. select a random element array[rand() % array.size]

  20. select a random element array[rand() % array.size] UNIFORM distribution

  21. select a random element array[rand() % array.size] UNIFORM distribution

  22. select a random element array[rand() % array.size] UNIFORM distribution AGHHH

  23. This is how you kill the RANDOM pnrg array

  24. This is how you kill the RANDOM a pnrg array

  25. This is how you kill the RANDOM a pnrg array

  26. This is how you kill the RANDOM a a pnrg

    array
  27. This is how you kill the RANDOM a a pnrg

    array
  28. This is how you kill the RANDOM a a a

    pnrg array
  29. This is how you kill the RANDOM a a a

    pnrg array
  30. This is how you kill the RANDOM a a a

    pnrg array
  31. This is how you kill the RANDOM a a a

    b pnrg array
  32. This is how you kill the RANDOM a a a

    b pnrg array
  33. This is how you kill the RANDOM a a a

    b b pnrg array
  34. This is how you kill the RANDOM a a a

    b b pnrg array
  35. This is how you kill the RANDOM a a a

    b b pnrg array
  36. This is how you kill the RANDOM a a a

    b b pnrg array
  37. how to FIX:

  38. how to FIX: 1. Random is hard

  39. how to FIX: 1. Random is hard 2. Run away

  40. how to FIX: 1. Random is hard 2. Run away

    Math.random() // between 0.0 and 1.0 Javascript
  41. how to FIX: 1. Random is hard 2. Run away

  42. how to FIX: 1. Random is hard 2. Run away

    prng.rand(5..9) #=> one of [5, 6, 7, 8, 9] prng.rand(5...9) #=> one of [5, 6, 7, 8] Ruby
  43. Good.

  44. Good. (but I don’t care)

  45. None
  46. “PRNGs and Hash functions are in the same family of

    algorithms”
  47. None
  48. hash tables out of nowhere!

  49. hash tables out of nowhere! O(1)

  50. hash tables out of nowhere! O(1) uniform

  51. pathological average data set: O(1)

  52. pathological average data set: O(1)

  53. pathological average data set: O(1) O(n)

  54. ONE fix

  55. ONE fix INT_MAX % size == 0

  56. collide make them

  57. collide make them • Brute force

  58. collide make them • Brute force • MITM

  59. collide make them • Brute force • MITM • Equivalent

    substrings
  60. collide make them • Brute force • MITM • Equivalent

    substrings
  61. collide make them • Brute force • MITM • Equivalent

    substrings
  62. collide make them • Brute force • MITM • Equivalent

    substrings
  63. collide make them • Brute force • MITM • Equivalent

    substrings
  64. collide make them • Brute force • MITM • Equivalent

    substrings
  65. problem & that’s a

  66. problem & that’s a painful comparisons

  67. problem & that’s a painful comparisons ~700ms responses

  68. MANY fixes

  69. MANY fixes (but only one is right)

  70. MANY fixes (but only one is right) 1. Limiting request

    size
  71. this is bad and you should feel bad! MANY fixes

    (but only one is right) 1. Limiting request size
  72. MANY fixes (but only one is right) 2. Changing the

    hash table
  73. MANY fixes (but only one is right) 2. Changing the

    hash table (no comment)
  74. MANY fixes (but only one is right) 3. Bring back

    the random
  75. None
  76. “Randomness is too important to be left to chance”

  77. Thanks. “Randomness is too important to be left to chance”