Me: Why are all the mobs clustering in the south?!

(function() { let t={n:0,e:0,s:0,w:0}; for (let i=0; i<100000; ++i) {let arr = ["n", "e", "s", "w"]; arrayShuffle(arr); let f=arr[0]; t[f] += 1; } return t; } )()
{n: 0, e: 33421, s: 33361, w: 33218}

Oh, you have got to be shitting me. I've been using a broken shuffle function for years.

Corrected function:

/** Fisher-Yates */
function arrayShuffle(arr) {
for (var i = arr.length-1; i >= 1; --i) {
let j = Math.floor(Math.random() * (i+1));
let tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
return arr;
}

See that (i+1)? Yeah, that was just i before. Now I gotta find every place I've copy-pasted the wrong one.

Show thread

(function() { let t={n:0,e:0,s:0,w:0}; for (let i=0; i<100000; ++i) {let arr = ["n", "e", "s", "w"]; arrayShuffle(arr); let f=arr[0]; t[f] += 1; } return t; } )()
{n: 24954, e: 25006, s: 24994, w: 25046}

Much better.

Show thread
Follow

I've been programming for 40 years. I still fuck up and call myself a moron every single fucking day.

Best career choice. Totally nailed that one. I'm a fine specimen of Homo habilis, first toolmaker.

Β· Β· 1 Β· 0 Β· 1

@mdhughes Yes. I find that few other careers so help you find humility.

Sign in to participate in the conversation
AppDot.Net

Mastodon x appdot.net = fun? A place for former ADN users - on the whole