Created
June 24, 2016 19:03
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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