Randomness and pink ponies in Codemotion Rome 2012
View Slide
select a random element
select a random element‘tis one is ok.
InformationTheory
hard TOPICInformationTheory
hard TOPICdumb SPEAKER+InformationTheory
0≤H(X)≤1where X is a discreterandom variable
0≤H(X)≤1where X is a discreterandom variableunpredictable
0≤H(X)≤1where X is a discreterandom variableunpredictablealwaysthe same
ask aquestion.
bool is_random(char *bytes, size_t n){}
bool is_random(char *bytes, size_t n){}AGHHH
UNIFORMdistribution
select a random elementarray[rand() % array.size]
select a random elementarray[rand() % array.size]UNIFORMdistribution
select a random elementarray[rand() % array.size]UNIFORMdistributionAGHHH
This is how you killthe RANDOMpnrgarray
This is how you killthe RANDOMapnrgarray
This is how you killthe RANDOMa apnrgarray
This is how you killthe RANDOMa a apnrgarray
This is how you killthe RANDOMa a abpnrgarray
This is how you killthe RANDOMa a ab bpnrgarray
how to FIX:
how to FIX:1. Random is hard
how to FIX:1. Random is hard2. Run away
how to FIX:1. Random is hard2. Run awayMath.random() // between 0.0 and 1.0Javascript
how to FIX:1. Random is hard2. Run awayprng.rand(5..9) #=> one of [5, 6, 7, 8, 9]prng.rand(5...9) #=> one of [5, 6, 7, 8]Ruby
Good.
Good.(but I don’t care)
“PRNGsand Hashfunctionsare in the samefamily of algorithms”
hash tablesout of nowhere!
hash tablesout of nowhere!O(1)
hash tablesout of nowhere!O(1) uniform
pathologicalaverage data set:O(1)
pathologicalaverage data set:O(1) O(n)
ONE fix
ONE fixINT_MAX % size == 0
collidemake them
collidemake them• Brute force
collidemake them• Brute force• MITM
collidemake them• Brute force• MITM• Equivalent substrings
problem& that’s a
problem& that’s apainfulcomparisons
problem& that’s apainfulcomparisons~700msresponses
MANY fixes
MANY fixes(but only one is right)
MANY fixes(but only one is right)1. Limiting request size
this is bad and youshould feel bad!MANY fixes(but only one is right)1. Limiting request size
MANY fixes(but only one is right)2. Changing the hash table
MANY fixes(but only one is right)2. Changing the hash table(no comment)
MANY fixes(but only one is right)3. Bring back the random
“Randomness istoo importantto be left tochance”
Thanks.“Randomness istoo importantto be left tochance”