Skip to content

Instantly share code, notes, and snippets.

@mathewsanders
Last active August 29, 2015 14:06
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 mathewsanders/423c975f50c7e5cfa61c to your computer and use it in GitHub Desktop.
Save mathewsanders/423c975f50c7e5cfa61c to your computer and use it in GitHub Desktop.
Playground for random numbers
// 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