Created
April 18, 2012 14:01
-
-
Save furf/2413792 to your computer and use it in GitHub Desktop.
Select a random letter from A to Z based on letter frequency in the English language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var randomAtoZ = (function (lookup) { | |
return function () { | |
var random = Math.random() * 100000, | |
letter; | |
for (letter in lookup) { | |
if (random < lookup[letter]) { | |
return letter; | |
} | |
} | |
} | |
})({ | |
// Ranges calculated from data found at | |
// http://en.wikipedia.org/wiki/Letter_frequency | |
a: 8167, b: 9659, c: 12441, d: 16694, | |
e: 29396, f: 31624, g: 33639, h: 39733, | |
i: 46699, j: 46852, k: 47624, l: 51649, | |
m: 54055, n: 60804, o: 68311, p: 70240, | |
q: 70335, r: 76322, s: 82649, t: 91705, | |
u: 94463, v: 95441, w: 97801, x: 97951, | |
y: 99925, z: 100000 | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment