Demo entry 6347736

extension

   

Submitted by anonymous on Feb 16, 2017 at 12:50
Language: Swift. Code size: 295 Bytes.

extension Array {
    public mutating func shuffle() {
        for i in stride(from: count - 1, through: 1, by: -1) {
            let random = Int(arc4random_uniform(UInt32(i+1)))
            if i != random {
                swap(&self[i], &self[random])
            }
        }
    }
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).