Created
April 28, 2016 02:33
-
-
Save robseward/cd3e1cb88e0d7ac34299576fc1b7536a to your computer and use it in GitHub Desktop.
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 UIKit | |
var analogValue: Double = 0.00 | |
let max = 1.0 | |
var binaryOut = 0 | |
for _ in (0...100) { | |
let thermalNoise = Double((arc4random() % 1000)) / 100000 | |
analogValue += thermalNoise | |
if analogValue <= 0.5 { | |
analogValue *= 1.8 | |
} | |
else { | |
analogValue = analogValue - (max - analogValue) | |
} | |
binaryOut = Int(analogValue > 0.5) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment