ç¹å®ã®ç¯å²ã®ä¹±æ°ãæ±ããéã«ã¯ãObjective-Cã¨åãããã«arc4randomé¢æ°
ã使ããã¨ãã§ãã¾ãã
//0ãã9ã¾ã§ã®å¤ãåå¾ãã let random = arc4random() % 10
ä¸è¨ã®ã³ã¼ãã§ã¯arc4randomé¢æ°
ã§å¾ãä¹±æ°ã®ä½å°ãæ±ãã¦ãããããarc4randomé¢æ°
ã§ã¯çæãããä¹±æ°ã«ããåããçºçãã¦ãã¾ãã¾ãã
äºåã«0ãã9ã¾ã§ã®å¤ã欲ããã¨ãããã¨ãåãã£ã¦ããã®ã§ããã°ãarc4random_uniformé¢æ°
ã使ãã¨è¯ãã§ãããã
//0ãã9ã¾ã§ã®å¤ãåå¾ãã let random = arc4random_uniform(10)
ä¾ãã°ãStringåã®é åããã©ã³ãã ã«1ã¤åãåºãå ´åã«ã¯ä»¥ä¸ã®ããã«æ¸ããã¨ãã§ãã¾ãã
var titles: [String] = [ "ã»ã", "ã½ã", "ã´ã", "ã·ã" ] let index = (Int)(arc4random_uniform(4)) println("\(titles[index])")
Objective-Cã§ä¹±æ°ãçæããå ´åã¯ä»¥ä¸ã®è¨äºã御覧ãã ããã