[BitArray] random(count:using:) → randomBits(count:using:)

This commit is contained in:
Karoy Lorentey committed 2023-01-31 17:33:55 -08:00
1 parent 6cb03fee98
commit 03b62ffb6e
1 file changed
+7 -6
@@ -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<R: RandomNumberGenerator>(
public static func randomBits<R: RandomNumberGenerator>(
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) }