Skip to content

Instantly share code, notes, and snippets.

@robseward
Created April 28, 2016 02:33
Show Gist options
  • Save robseward/cd3e1cb88e0d7ac34299576fc1b7536a to your computer and use it in GitHub Desktop.
Save robseward/cd3e1cb88e0d7ac34299576fc1b7536a to your computer and use it in GitHub Desktop.
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