2014년 9월 30일 화요일

random


1.  0~10 까지의 랜덤 숫자

uint32_t random = arc4random_uniform(11);

2.  50~100 까지의 랜덤 숫자

uint32_t random = arc4random_uniform(51)+50;




3.  랜덤 숫자

unsigned int random = arc4random();


4. 컬러값 랜덤으로 가져오기

static func randomBackgroundColor() -> UIColor {
        let colors = [UIColor.rgb(5, 200, 123), UIColor.rgb(176, 158, 145), UIColor.rgb(106, 97, 248), UIColor.rgb(33, 173, 254), UIColor.rgb(249, 135, 40)]
        let randomIndex = Int(arc4random_uniform(UInt32(colors.count)))
        return colors[randomIndex]

    }

댓글 없음:

댓글 쓰기