Last active
December 14, 2015 01:39
-
-
Save ykarikos/5007429 to your computer and use it in GitHub Desktop.
Select random letters according to the distribution of letters in Finnish language
This file contains hidden or 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
/** | |
* Select random letters according to the distribution of letters in Finnish language: | |
* https://docs.google.com/spreadsheet/ccc?key=0AiZHeDrg3BuddFZfTXVnclQ5UWNkaGVuWmdVT3dzMEE&usp=sharing | |
* Ignore the uncommon letters c, z, w, q, x and å | |
*/ | |
import scala.util.Random | |
object RandomLetters { | |
val rnd = Random | |
def nextLetter(alphabet: List[(Double, String)]): String = { | |
val r = rnd.nextDouble() | |
alphabet.find(_._1 > r).get._2 | |
} | |
def main(args: Array[String]) { | |
val alphabet = | |
List((0.11607, "I"), (0.23011, "A"), (0.31651, "T"), (0.39098, "S"), (0.45836, "E"), | |
(0.52488, "U"), (0.59058, "K"), (0.65494, "N"), (0.71334, "L"), (0.76748, "O"), | |
(0.80699, "R"), (0.83889, "Ä"), (0.86920, "P"), (0.89892, "M"), (0.92313, "V"), | |
(0.94481, "H"), (0.96644, "Y"), (0.97941, "J"), (0.98683, "D"), (0.99417, "Ö"), | |
(0.99682, "G"), (0.99847, "F"), (1.00000, "B")) | |
val letters = List.fill(1000000)(nextLetter(alphabet)). | |
groupBy(identity).mapValues(_.size).toList.sortWith((a,b) => (a._2 > b._2)) | |
letters.foreach(n => println(n._1, n._2/10000.0)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment