-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Types that conform to RandomRetrievable can have any random element be taken from an instance. The `uncheckedRandom(using:)` method is unsafe. It is a serious programming error to use it on an empty sequence. The RandomRetrievableInRange protocol allows for getting random elements from within a given index range. It is also a serious programming error to use `uncheckedRandom(in:using:)` when the sequence or range is empty or the range is out of bounds. This removes `random(using:)` that could previously be used on any Sequence. In theory, any Sequence can conform to RandomRetrievable and RandomRetrievableInRange given Array's conformance to these protocols. However, it would hide the horrible performance involved with allocating memory for all elements of a sequence just to get a single random value out. This is even worse when multiple random values are needed and thus multiple arrays are allocated. Types such as lazy sequence types will be able to conform to these protocols once conditional conformance is implemented (SE-0143).
- Loading branch information
Showing
11 changed files
with
251 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.