SORandom 随机数生成器

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)!

 

© 版权声明
THE END
喜欢就支持一下吧
点赞873 分享
Judge each day not by the harvest you reap but by the seeds you plant.
不要问自己收获了多少果实,而是要问自己今天播种了多少种子