Last active
August 29, 2015 14:06
-
-
Save mathewsanders/423c975f50c7e5cfa61c to your computer and use it in GitHub Desktop.
Playground for random numbers
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
// Playground - noun: a place where people can play | |
import UIKit | |
// delay is type NSTimeInterval (alias for type 'Double') | |
var delay:NSTimeInterval | |
// random number btween 1.0 and 20.0 | |
delay = NSTimeInterval(arc4random_uniform(20)) | |
// random number btween 0.0 and 1.0 | |
delay = NSTimeInterval(arc4random_uniform(10)) / 10 | |
// increase precision by using a larger divisor | |
// random number btween 0.000 and 1.000 | |
delay = NSTimeInterval(arc4random_uniform(1000)) / 1000 | |
// random number btween 0.250 and 0.500 | |
delay = NSTimeInterval(250 + arc4random_uniform(250)) / 1000 | |
// random number btween 0.900 and 1.000 | |
delay = NSTimeInterval(900 + arc4random_uniform(100)) / 1000 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment