I don't really get why a * 51 & 52
evaluates to false
for 9, 14, 19, 24 in the code beneath. I understand that the interval is 5 but why is 51 and 52 used and what numbers would I use for e.g. an interval of 6?
for( // loop :)
b=a=''; // b - result , a - numeric variable
a++<36; //
b+=a*51&52 // if "a" is not 9 or 14 or 19 or 24
? // return a random number or 4
(
a^15 // if "a" is not 15
? // genetate a random number from 0 to 15
8^Math.random()*
(a^20?16:4) // unless "a" is 20, in which case a random number from 8 to 11
:
4 // otherwise 4
).toString(16)
:
'-' // in other cases (if "a" is 9,14,19,24) insert "-"
);
return b
Update 25/08/2014 at 15:35: Sorry, maybe my question was a bit unclear. I wanted a logical or mathematical explanation why the bitwise comparison only evaluates to false for 9, 14, 19, 24. I'm aware of what the bitwise operator does and how it works but I really don't get the logic of the used pattern above. The code is actually taken from a gist to generate random v4 UUIDs (see https://gist.github.com/LeverOne/1308368) and I would name it size optimised code rather than obfuscated code.