File tree Expand file tree Collapse file tree 2 files changed +7
-2
lines changed
Tests/SwiftAlgorithmsTests Expand file tree Collapse file tree 2 files changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -87,14 +87,14 @@ extension Collection {
87
87
internal func nextW< G: RandomNumberGenerator > (
88
88
k: Int , using rng: inout G
89
89
) -> Double {
90
- Double . root ( . random( in: 0 ..< 1 , using: & rng) , k)
90
+ Double . root ( 1 - . random( in: 0 ..< 1 , using: & rng) , k)
91
91
}
92
92
93
93
@usableFromInline
94
94
internal func nextOffset< G: RandomNumberGenerator > (
95
95
w: Double , using rng: inout G
96
96
) -> Int {
97
- Int ( Double . log ( . random( in: 0 ..< 1 , using: & rng) ) / . log( 1 - w) )
97
+ Int ( Double . log ( 1 - . random( in: 0 ..< 1 , using: & rng) ) / . log( 1 - w) )
98
98
}
99
99
100
100
extension Collection {
Original file line number Diff line number Diff line change @@ -95,4 +95,9 @@ final class RandomSampleTests: XCTestCase {
95
95
let sample2c = c. randomStableSample ( count: k, using: & generator)
96
96
XCTAssertEqual ( sample1c, sample2c)
97
97
}
98
+
99
+ func testRandomSampleZeroRandom( ) {
100
+ var generator = SplitMix64 ( seed: 0x61c8864680b583eb ) // this seed starts with 0
101
+ _ = c. randomSample ( count: k, using: & generator) // must not crash
102
+ }
98
103
}
You can’t perform that action at this time.
0 commit comments