我在结构中使用GKRandomSource
在视图中返回一个随机励志名言。有没有办法返回这个随机数并省略之前的输入?这样用户不会连续两次收到相同的报价。使用GKRandomSource生成随机数
let inspiration = [
"You are looking rather nice today, as always.",
"Hello gorgeous!",
"You rock, don't ever change!",
"Your hair is looking on fleek today!",
"That smile.",
"Somebody woke up on the right side of bed!"]
func getRandomInspiration() -> String {
let randomNumber = GKRandomSource.sharedRandom().nextIntWithUpperBound(inspiration.count)
return inspiration[randomNumber]
}
最好有每次数组的副本和你采取随机索引,从数组中删除它,然后随机从0到新的阵列大小 – Fonix