From 3d72775b3c5100a44e441eda89120b7de920af45 Mon Sep 17 00:00:00 2001 From: Phil Crosby Date: Fri, 20 Jan 2012 00:48:03 -0800 Subject: Scatter the link hints less naively. --- linkHints.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'linkHints.js') diff --git a/linkHints.js b/linkHints.js index f30425aa..24fa7946 100644 --- a/linkHints.js +++ b/linkHints.js @@ -352,7 +352,23 @@ var alphabetHints = { for (var i = start; i < start + longHintCount; i++) hintStrings.push(this.numberToHintString(i, digitsNeeded, linkHintCharacters)); - return hintStrings; + return this.shuffleHints(hintStrings, linkHintCharacters.length); + }, + + /* + * This shuffles the given set of hints so that they're scattered -- hints starting with the same character + * will be spread evenly throughout the array. + */ + shuffleHints: function(hints, characterSetLength) { + var buckets = [], i = 0; + for (i = 0; i < characterSetLength; i++) + buckets[i] = [] + for (i = 0; i < hints.length; i++) + buckets[i % buckets.length].push(hints[i]); + var result = []; + for (i = 0; i < buckets.length; i++) + result = result.concat(buckets[i]); + return result; }, /* -- cgit v1.2.3