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