Vicent Martí
March 25, 2012
2.4k

# Oh, you're so random

Randomness and pink ponies in Codemotion Rome 2012

March 25, 2012

## Transcript

1. select a random element

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

3. Information
Theory

4. hard TOPIC
Information
Theory

5. hard TOPIC
dumb SPEAKER
+
Information
Theory

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

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

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

question.

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

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

12. UNIFORM
distribution

13. UNIFORM
distribution

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

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

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

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

18. This is how you kill
the RANDOM
pnrg
array

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

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

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

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

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

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

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

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

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

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

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

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

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

32. how to FIX:

33. how to FIX:
1. Random is hard

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

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

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

37. 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

38. Good.

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

40. “PRNGs
and Hash
functions
are in the same
family of algorithms”

41. hash tables
out of nowhere!

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

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

44. pathological
average data set:
O(1)

45. pathological
average data set:
O(1)

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

47. ONE fix

48. ONE fix
INT_MAX % size == 0

49. collide
make them

50. collide
make them
• Brute force

51. collide
make them
• Brute force
• MITM

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

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

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

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

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

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

58. problem
& that’s a

59. problem
& that’s a
painful
comparisons

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

61. MANY fixes

62. MANY fixes
(but only one is right)

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

64. this is bad and you
MANY fixes
(but only one is right)
1. Limiting request size

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

66. MANY fixes
(but only one is right)
2. Changing the hash table
(no comment)

67. MANY fixes
(but only one is right)
3. Bring back the random

68. “Randomness is
too important
to be left to
chance”

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