gpt4 book ai didi

swift - 使用 Swift 生成随机数

转载 作者:IT王子 更新时间:2023-10-29 04:56:55 25 4
gpt4 key购买 nike

我需要生成一个随机数。

出现了 arc4random函数以及 arc4random_uniform 不再存在功能。

我的选项是 arc4random_stir() , arc4random_buf(UnsafeMutablePointer<Void>, Int) , 和 arc4random_addrandom(UnsafeMutablePointer<UInt8>, Int32) .

我找不到关于函数的任何文档,头文件中的注释也没有给出提示。

最佳答案

let randomIntFrom0To10 = Int.random(in: 1..<10)
let randomFloat = Float.random(in: 0..<1)

// if you want to get a random element in an array
let greetings = ["hey", "hi", "hello", "hola"]
greetings.randomElement()

关于swift - 使用 Swift 生成随机数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32552336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com