Skip to content

Instantly share code, notes, and snippets.

@abarrak
Created January 13, 2017 18:12
Show Gist options
  • Select an option

  • Save abarrak/85697103b1a7a6d1579fec3e4f2a72d0 to your computer and use it in GitHub Desktop.

Select an option

Save abarrak/85697103b1a7a6d1579fec3e4f2a72d0 to your computer and use it in GitHub Desktop.
Ruby's sample in swift lang
//
// ArrayExtension.swift
// Brings sample() to swift
//
// Created by Abdullah on 10/3/16.
//
import Foundation
extension Array {
func sample() -> Element {
srandom(UInt32(time(nil)))
return self[random() % self.count]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment