diff --git a/Sources/BitCollections/BitArray/BitArray+Random.swift b/Sources/BitCollections/BitArray/BitArray+RandomBits.swift similarity index 77% rename from Sources/BitCollections/BitArray/BitArray+Random.swift rename to Sources/BitCollections/BitArray/BitArray+RandomBits.swift index 5c58cf78..9a13e78c 100644 --- a/Sources/BitCollections/BitArray/BitArray+Random.swift +++ b/Sources/BitCollections/BitArray/BitArray+RandomBits.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2022 Apple Inc. and the Swift project authors +// Copyright (c) 2022-2023 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -10,12 +10,13 @@ //===----------------------------------------------------------------------===// extension BitArray { - /// Create and return a new bit array consisting of `count` random bits. + /// Create and return a new bit array consisting of `count` random bits, + /// using the system random number generator. /// /// - Parameter count: The number of random bits to generate. - public static func random(count: Int) -> BitArray { + public static func randomBits(count: Int) -> BitArray { var rng = SystemRandomNumberGenerator() - return random(count: count, using: &rng) + return randomBits(count: count, using: &rng) } /// Create and return a new bit array consisting of `count` random bits, @@ -23,11 +24,11 @@ extension BitArray { /// /// - Parameter count: The number of random bits to generate. /// - Parameter rng: The random number generator to use. - public static func random( + public static func randomBits( count: Int, using rng: inout R ) -> BitArray { - precondition(count >= 0, "Invalid capacity value") + precondition(count >= 0, "Invalid count") guard count > 0 else { return BitArray() } let (w, b) = _BitPosition(count).endSplit var words = (0 ... w).map { _ in _Word(rng.next() as UInt) }