How does one generate a random number in Apple's Swift language?

后端 未结 25 1992
有刺的猬
有刺的猬 2020-11-22 09:51

I realize the Swift book provided an implementation of a random number generator. Is the best practice to copy and paste this implementation in one\'s own program? Or is t

25条回答
  •  借酒劲吻你
    2020-11-22 10:22

    I've been able to just use rand() to get a random CInt. You can make it an Int by using something like this:

    let myVar: Int = Int(rand())
    

    You can use your favourite C random function, and just convert to value to Int if needed.

提交回复
热议问题