Commit Graph

7 Commits

Author SHA1 Message Date
Stephen Canon
8736683cf7 Prevent arbitrary objects from conforming to RNG. (#36969)
Me, sobbing: "Look, you can't just point at an empty struct and call it a RandomNumberGenerator."
Swift 5.4, pointing at anything: "RNG."
2021-04-20 16:39:16 -04:00
Karoy Lorentey
c03fe15caf [test] Move Random tests under validation-test
StdlibCollectionUnittest is not available in smoke tests.
2018-05-10 19:47:14 +01:00
Karoy Lorentey
12a2b32644 [stdlib] Add & implement Random._fill(bytes:) requirement 2018-05-09 17:51:36 +01:00
Ben Rimmington
b65d0c1d11 Consolidate _stdlib_random functions (#2)
* Use the `__has_include` and `GRND_RANDOM` macros

* Use `getentropy` instead of `getrandom`

* Use `std::min` from the <algorithm> header

* Move `#if` out of the `_stdlib_random` function

* Use `getrandom` with "/dev/urandom" fallback

* Use `#pragma comment` to import "Bcrypt.lib"

* <https://docs.microsoft.com/en-us/cpp/preprocessor/comment-c-cpp>
* <https://clang.llvm.org/docs/UsersManual.html#microsoft-extensions>

* Use "/dev/urandom" instead of `SecRandomCopyBytes`

* Use `swift::StaticMutex` for shared "/dev/urandom"

* Add `getrandom_available`; use `O_CLOEXEC` flag

Add platform impl docs

Update copyrights

Fix docs

Add _stdlib_random test

Update _stdlib_random test

Add missing &

Notice about _stdlib_random

Fix docs

Guard on upperBound = 0

Test full range of 8 bit integers

Remove some gyb

Clean up integerRangeTest

Remove FixedWidthInteger constraint

Use arc4random universally

Fix randomElement

Constrain shuffle to RandomAccessCollection

warning instead of error

Move Apple's implementation

Fix failing test on 32 bit systems
2018-05-09 00:21:44 -05:00
Nate Cook
f146d17214 Revise documentation, add benchmarks (#3)
* [stdlib] Revise documentation for new random APIs

* [stdlib] Fix constraints on random integer generation

* [test] Isolate failing Random test

* [benchmark] Add benchmarks for new random APIs

Fix Float80 test

Value type generators

random -> randomElement

Fix some docs

One more doc fix

Doc fixes & bool fix

Use computed over explicit
2018-05-04 21:03:50 -05:00
Ben Rimmington
a5df0ef83d Add _stdlib_random for more platforms (#1)
* Remove refs to Countable ranges

* Add `_stdlib_random` for more platforms

* Use `getrandom` (if available) for Android, Cygwin

* Reorder the `_stdlib_random` functions

* Also include <features.h> on Linux

* Add `#error TODO` in `_stdlib_random` for Windows

* Colon after Fatal Error

Performance improvement for Random

gybify ranges

Fix typo in 'basic random numbers'
Add _stdlib_random as a testable method

Switch to generic constraints

Hopefully link against bcrypt

Fix some implementation details

1. Uniform distribution is now uniform
2. Apply Jens' method for uniform floats

Fix a lineable attribute
2018-05-04 21:03:38 -05:00
Azoy
d23d219e95 Add shims for stdlib random
Initial random api

Use C syscall for I/O

1. Fixed an issue where integers would would result in an infinite loop if they were unsigned, or signed integers always returning negative numbers.
2. Fixed an issue with Bool initialization

Add shuffle functions

Add documentation to Random API

Fix a few typos within the documentation

Fixes more typos

Also states that the range for floating points is from 0 to 1 inclusive

Update API to reflect mailing list discussions

Remove unnecessary import

Make sure not to return upperBound on Range

Use SecRandomCopyBytes on older macOS

Update API to match mailing list discussion, add tests

Added pick(_:) to collection
Added random(in:using:) to Randomizable
Added tests

Fix typo in Randomizable documentation

Rename pick to sampling

Move sampling below random

Update docs

Use new Libc naming

Fix Random.swift with new Libc naming

Remove sampling

gybify signed integer creation

Make FloatingPoint.random exclusive

Refactor {Closed}Range.random

Fix FloatingPoint initialization

Precondition getting a random number from range

Fix some doc typos

Make .random a function

Update API to reflect discussion

Make .random a function
Remove .random() in favor of .random(in:) for all numeric types

Fix compile errors

Clean up _stdlib_random

Cleanup around API

Remove `.random()` requirement from `Collection`

Use generators

Optimize shuffle()

Thread safety for /dev/urandom

Remove {Closed}Range<BinaryFloatingPoint>.random()

Add Collection random requirement

Refactor _stdlib_random

Remove whitespace changes

Clean linux shim

Add shuffle and more tests

Provide finishing tests and suggestions

Remove refs to Countable ranges

Revert to checking if T is > UInt64
2018-05-04 21:02:57 -05:00