SwiftRandom 介绍
SwiftRandom 是一组函数集合,可以从不同的分布生成伪随机变量。
使用示例:
//Single pseudorandom normal variable //with mean 0 and standard deviation 1 let x = SwiftRandom.randomnormal(mean: 0, standardDeviation: 1)! //Array of pseudorandom independent normal variables //with mean 0 and standard deviation 1 and length 10 let sample = SwiftRandom.randomnormalArray(mean: 0, standardDeviation: 1, sampleLength: 10)! //Sampling from array: //with replacement let numbers = [10, 11, 45, 1, 0, 4] let bootstrapSample = SwiftRandom.samplingWithReplacementFromArray(numbers, sampleLength: 10)! //without replacement let names = ["John", "Bob", "Anna", "Alice", "Chris", "Luke"] let usersOrder = SwiftRandom.samplingWithoutReplacementFromArray(names, sampleLength: 4)!
SwiftRandom 官网
https://github.com/SebastianOsinski/SwiftRandom
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。