Sampling a random subset from an array

I suggest shuffling a copy of the array using the Fisher-Yates shuffle and taking a slice: function getRandomSubarray(arr, size) { var shuffled = arr.slice(0), i = arr.length, temp, index; while (i–) { index = Math.floor((i + 1) * Math.random()); temp = shuffled[index]; shuffled[index] = shuffled[i]; shuffled[i] = temp; } return shuffled.slice(0, size); } var x … Read more

Is there special significance to 16331239353195370.0?

pi isn’t exactly representable as Python float (same as the platform C’s double type). The closest representable approximation is used. Here’s the exact approximation in use on my box (probably the same as on your box): >>> import math >>> (math.pi / 2).as_integer_ratio() (884279719003555, 562949953421312) To find the tangent of that ratio, I’m going to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)