Implement Random core class and random functions in Kernel #384
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit implements all APIs of
Random
except for the internalprivate method
Random#state
andRandom::Formatter
.Random is implemented with the
rand
crate's not cryptographicallysecure
SmallRng
. For cryptographically secure APIs likeRandom::urandom
, the re-seedingrand::thread_rng
is used.Random
is gated behind a crate feature.To support the
Random::DEFAULT
interpreter-widre PRNG, the interpreterstores a
Random
on theState
and injects a special backend to allowthe
DEFAULT
constant to target thisState
-ownedRandom
.Random
is implemented with multiple backends and has a small API whichwould make supporting a future CRuby algorithm possible. The
Rand
backend is generic over the
rand::Rng
implementation.This commit passes 30 ruby/specs and fails 14:
The specs that fail fall into the following categories:
Encoding
not implemented, particularlyEncoding::ASCII-8BIT
.This PR does some small refactorings:
Value::implicitly_convert_to_int
to simplify arg handlingin
random
trampoline. All of Artichoke is not fully migrated.Float
type alias from float converter totypes
module.This PR implements the
Random
core class andKernel
randomfunctions. This PR is a partial implementation of GH-34.