<commit_before>import Foundation
import AVFoundation

class HuntForKey : Mode {

    let synthesizer = AVSpeechSynthesizer()

    let letters = Array("abcdefghijklmnopqrstuvwxyz")
    var targetKey = ""
    
    func start()  {
        randomizeKey()
    }
    
    func respondTo(key: String)  {
        if(key == targetKey)
        {
            immediatelySay("Great job! You pressed the letter \(targetKey)")
            
            randomizeKey()
        }
        else
        {
            immediatelySay("No.  Try again.  Press the \(targetKey) key")
        }
    }
    
    func randomizeKey () {
        let randomLetterIndex = Int.random(in: 0 ..< letters.count)
        targetKey = String(letters[randomLetterIndex])
        
        say("Press the \(targetKey) key")
    }
    
    func say(_ word: String) {
        let utterance = AVSpeechUtterance(string: word.lowercased())
        synthesizer.speak(utterance)
    }
    
    func immediatelySay(_ word: String) {
        let utterance = AVSpeechUtterance(string: word.lowercased())
        synthesizer.stopSpeaking(at: .immediate)
        synthesizer.speak(utterance)
    }
    
}<commit_msg>Collapse random letter selection with the new Arrays.randomElement()<commit_after>import Foundation
import AVFoundation

class HuntForKey : Mode {

    let synthesizer = AVSpeechSynthesizer()

    let letters = Array("abcdefghijklmnopqrstuvwxyz")
    var targetKey = ""
    
    func start()  {
        randomizeKey()
    }
    
    func respondTo(key: String)  {
        if(key == targetKey)
        {
            immediatelySay("Great job! You pressed the letter \(targetKey)")
            
            randomizeKey()
        }
        else
        {
            immediatelySay("No.  Try again.  Press the \(targetKey) key")
        }
    }
    
    func randomizeKey () {
        targetKey = String(letters.randomElement()!)
        
        say("Press the \(targetKey) key")
    }
    
    func say(_ word: String) {
        let utterance = AVSpeechUtterance(string: word.lowercased())
        synthesizer.speak(utterance)
    }
    
    func immediatelySay(_ word: String) {
        let utterance = AVSpeechUtterance(string: word.lowercased())
        synthesizer.stopSpeaking(at: .immediate)
        synthesizer.speak(utterance)
    }
    
}
{'fraction_non_alphanumeric': 0.0978778692074491, 'fraction_numerical': 0.00043308791684711995, 'mean_word_length': 2.0677290836653386, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3198137', 'n_tokens_mistral': 705, 'n_tokens_neox': 684, 'n_words': 146}