BOOLを割合を決めてランダムで取得する
Objective-cの場合
.m
BOOL randomBoolWithYesPercent(int percent) {
return arc4random_uniform(100) < percent;
}
Swiftの場合
.swift
func randomBoolWithYesPercent(percent: UInt32) -> Bool {
return arc4random_uniform(100) < percent
}
intを最大値を決めてランダムで取得する
Objective-cの場合
.m
int randomIntWithMax(int max) {
return arc4random_uniform(max + 1);
}
Swiftの場合
.swift
func randomIntWithMax(max: UInt32) -> UInt32 {
return arc4random_uniform(max + 1)
}
Swiftの書き方がまだよくわかっていないので
間違ってたらごめんなさい