You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The documentation for this standard library could be improved in a few ways. Discussion of modern constructor syntax for type conversions should be included (like `UInt32(value)` or `Int(value)` or whatever), as generally that is the preferred Swift language idiom over calling `numericCast`.
However, my main reason for filing the bug is the example code is outdated:
funcrandom(inrange: Range<Int>) -> Int {
returnnumericCast(arc4random_uniform(numericCast(range.count)))
+ range.lowerBound
}
It uses `numericCast` twice in the context of creating a random number generation function. Clearly, this example was written before the standard library incorporated native random APIs. This example should be changed to something outside of the random number domain, as inventing `random(in🙂` functions ad-hoc (and especially calls to `arc4random_uniform`) from Swift should no longer be encouraged as good practice.
The text was updated successfully, but these errors were encountered:
Additional Detail from JIRA
md5: e13604a2bc1f0808504231367a9bedab
Issue Description:
The documentation for this standard library could be improved in a few ways. Discussion of modern constructor syntax for type conversions should be included (like `UInt32(value)` or `Int(value)` or whatever), as generally that is the preferred Swift language idiom over calling `numericCast`.
However, my main reason for filing the bug is the example code is outdated:
It uses `numericCast` twice in the context of creating a random number generation function. Clearly, this example was written before the standard library incorporated native random APIs. This example should be changed to something outside of the random number domain, as inventing `
random(in🙂`
functions ad-hoc (and especially calls to `arc4random_uniform`) from Swift should no longer be encouraged as good practice.The text was updated successfully, but these errors were encountered: