Skip to content
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

faster rand(::Tuple) #32208

Merged
merged 2 commits into from
Sep 27, 2019
Merged

faster rand(::Tuple) #32208

merged 2 commits into from
Sep 27, 2019

Conversation

rfourquet
Copy link
Member

The idea is quite simple:

  • for powers of 2 lengths L, we do like for length 4, i.e. use a mask: rand(UInt32) & (L-1)
  • for others lengths, we fix an oversight which made rand(Base.OneTo(n)) (used in rand(::Tuple)) slower than rand(1:n) for MersenneTwister.

This breaks the reproducibility of generated streams, but we now have a precedent for that.

@rfourquet rfourquet added performance Must go faster randomness Random number generation and the Random stdlib minor change Marginal behavior change acceptable for a minor release labels May 31, 2019
This was an oversight.
This makes rand(::MersenneTwister, ::Tuple) generally faster.
@rfourquet
Copy link
Member Author

According to recent documentation, it's fine to change generated streams of random numbers for a given seed. Removing minor change label and merging.

@rfourquet rfourquet removed the minor change Marginal behavior change acceptable for a minor release label Sep 27, 2019
@rfourquet rfourquet merged commit 1c1000a into master Sep 27, 2019
@rfourquet rfourquet deleted the rf/rand/tuple-pow2 branch September 27, 2019 14:42
@StefanKarpinski StefanKarpinski added the minor change Marginal behavior change acceptable for a minor release label Sep 27, 2019
@StefanKarpinski
Copy link
Member

StefanKarpinski commented Sep 27, 2019

No, this is precisely what the "minor change" label is for: changes that are allowed in minor releases but not in patch releases. We do not promise random stream stability but we will not change the behavior of programs in point releases except to fix bugs.

@StefanKarpinski StefanKarpinski added the needs news A NEWS entry is required for this change label Sep 27, 2019
@StefanKarpinski
Copy link
Member

I've added the "needs news" label because minor changes should always be mentioned in NEWS.

rfourquet added a commit that referenced this pull request Sep 27, 2019
@rfourquet
Copy link
Member Author

Oops, sorry, I misunderstood! News added at #33404.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor change Marginal behavior change acceptable for a minor release needs news A NEWS entry is required for this change performance Must go faster randomness Random number generation and the Random stdlib
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants