Skip to content

Instantly share code, notes, and snippets.

@joswr1ght
Created June 24, 2016 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joswr1ght/d967529629d8e5ef4883bb5b05e2b363 to your computer and use it in GitHub Desktop.
Save joswr1ght/d967529629d8e5ef4883bb5b05e2b363 to your computer and use it in GitHub Desktop.
Demonstrate possible collection of emoji use data with random sampling for differential privacy
import Cocoa; import Foundation
func randomBool() -> Bool {
return arc4random_uniform(2) == 0 ? true: false
}
// A list of all emojis (
let emojis = ["πŸ˜€","😁","πŸ™πŸΎ","🐺","πŸƒ","πŸ›‚","πŸ’Έ","πŸ’°","πŸ’Ž","πŸŒ‚","πŸ‘","πŸ‘›","πŸ‘œ","πŸ†”","πŸŒ€","πŸ”»","πŸ’©"]
// A "collected list" of most used emojis
var mostUsedEmojis = ["πŸ’©","πŸ˜€","😁","πŸ’°","πŸŒ€"]
// Get a random True or False valuse
if randomBool() {
// Don't use collected customer emoji data, choose 5 random emojis instead
mostUsedEmojis = []
while(mostUsedEmojis.count < 5) {
var randEmoji = emojis[Int(arc4random_uniform(UInt32(emojis.count)))]
if !(mostUsedEmojis.contains(randEmoji)) {
mostUsedEmojis.append(randEmoji)
}
}
}
// "Send" emoji list to Apple
print(mostUsedEmojis)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment