﻿ 选择随机数的快速概率？ - 代码日志

#### 选择随机数的快速概率？

``````10% worse - 35% better then current item level = 55% chance
36% better to 90% better then current item level = 35% chance
91% better to 200% better then current item level = 5% chance
201% better to 500% better then current item level = 2.5% chance
500% better to 2000% better then current item level = 2.5% chance
``````

``````let randomNumber = Int(arc4random_uniform(1000))

if randomNumber <= 700 {
println("hey")
var newLevel = (Double(Double(randomNumber) / 700.00) + 0.1) * Double(pickDamage)

} else if randomNumber <= 800 && randomNumber > 700 {
var newLevel = (Double(Double(randomNumber) / 700.00) + 1.00) * Double(pickDamage)
} else if randomNumber <= 1000 && randomNumber > 950 {
var newLevel = (Double(Double(randomNumber) / 700.00) + 2.00) * Double(pickDamage)
}
``````

``````// create a random percent, with a precision of one decimal place
func randomPercent() -> Double {
return Double(arc4random() % 1000) / 10.0;
}

let randomNumber = randomPercent()
switch(randomNumber) {
case 0..<55:
println("10% worse - 35% better then current item level")
case 55..<90:
println("36% better to 90% better then current item level")
case 90..<95:
println("91% better to 200% better then current item level")
case 95..<97.5:
println("201% better to 500% better then current item level")
default:
println("500% better to 2000% better then current item level")
}
``````