Last active
October 20, 2021 02:40
-
-
Save orchetect/c9b883046dc717994b9edce1a66a6819 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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