-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[stdlib] Portable random function #1939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
_swift_stdlib_cxx11_mt19937_uniform(__swift_uint32_t upper_bound) { | ||
if (upper_bound > 0) | ||
upper_bound--; | ||
std::uniform_int_distribution<int> RandomUniform(0, upper_bound); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not std::uniform_int_distribution<__swift_uint32_t>
?
@tinysun212 LGTM, only minor comments! Let's test this as well: @swift-ci Please test |
@@ -105,7 +105,7 @@ func helperDeleteThree(k1: TestKeyTy, _ k2: TestKeyTy, _ k3: TestKeyTy) { | |||
} | |||
|
|||
func uniformRandom(max: Int) -> Int { | |||
return Int(arc4random_uniform(UInt32(max))) | |||
return Int(cxx11_mt19937_uniform(UInt32(max))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this should be calling rand32()
instead.
LGTM, let's merge. @swift-ci Please test and merge |
@tinysun212 Sorry! CI hit an error:
|
Changed rand32() implementation using a random engine in C++11 <random>.
b6c4e2f
to
5c1854b
Compare
Fixed and squashed. |
@swift-ci Please test and merge |
We were only using arc4random, and now we use C++ <random> instead. See also PR #1939.
SwiftPrivate/PRNG.swift: - currently uses `theGlobalMT19937`; - previously used `arc4random` (see swiftlang#1939); - is obsoleted by SE-0202: Random Unification.
What's in this pull request?
Resolved bug number: N/A
Before merging this pull request to apple/swift repository:
Triggering Swift CI
The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:
Smoke Testing
Validation Testing
Note: Only members of the Apple organization can trigger swift-ci.
Changed rand32() implementation using a random engine in C++11
<random>
.