<commit_before>import Foundation

func shuffleFisherYates(array: [Int]) -> [Int] {
    
    var shuffledArray = array
    for idx in 0 ..< array.count {
        let random = Int(arc4random_uniform(UInt32(array.count - idx))) + idx
        (shuffledArray[idx], shuffledArray[random]) = (shuffledArray[random], shuffledArray[idx])
    }
    
    return shuffledArray
}

let test = [1, 3, 5, 7, 9, 11, 13, 15, 17]

shuffleFisherYates(array: test)<commit_msg>Added random(range:) to FisherYates shuffle.<commit_after>import Foundation

// Borrowed from http://stackoverflow.com/questions/24132399/how-does-one-make-random-number-between-range-for-arc4random-uniform
func random(range: Range<Int> ) -> Int {
    var offset = 0
    
    if range.lowerBound < 0   // allow negative ranges
    {
        offset = abs(range.lowerBound)
    }
    
    let lower = UInt32(range.lowerBound + offset)
    let upper = UInt32(range.upperBound   + offset)
    
    return Int(lower + arc4random_uniform(upper - lower)) - offset
}

func shuffleFisherYates(array: [Int]) -> [Int] {
    
    var shuffledArray = array
    for idx in 0 ..< array.count {
        let randomIndex = random(range: idx ..< array.count)
        // Int(arc4random_uniform(UInt32(array.count - idx))) + idx
        (shuffledArray[idx], shuffledArray[randomIndex]) = (shuffledArray[randomIndex], shuffledArray[idx])
    }
    
    return shuffledArray
}

let test = [1, 3, 5, 7, 9, 11, 13, 15, 17]

shuffleFisherYates(array: test)
{'fraction_non_alphanumeric': 0.12727272727272726, 'fraction_numerical': 0.03367003367003367, 'mean_word_length': 3.1741573033707864, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, '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': '1454020', 'n_tokens_mistral': 531, 'n_tokens_neox': 484, 'n_words': 113}