Skip to content

Instantly share code, notes, and snippets.

@orchetect
Last active October 20, 2021 02:40
Show Gist options
  • Select an option

  • Save orchetect/c9b883046dc717994b9edce1a66a6819 to your computer and use it in GitHub Desktop.

Select an option

Save orchetect/c9b883046dc717994b9edce1a66a6819 to your computer and use it in GitHub Desktop.
import Foundation
/// Returns an array of random numbers. Values will be beween the range given, with an array size of `count`.
///
/// Example:
/// ```
/// [UInt8](randomValuesBetween: 0...255, count: 4) // [4,75,241,176]
/// ```
extension Array where Element : FixedWidthInteger {
@inlinable public init(randomValuesBetween: ClosedRange<Element>, count: Int) {
self.init()
reserveCapacity(count)
for _ in 0..<count {
self.append(Element.random(in: randomValuesBetween))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment