Skip to content

Rename WeightedError → WeightError; add IndexedRandom, IndexedMutRandom #1382

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

Merged
merged 8 commits into from
Feb 15, 2024

Conversation

dhardy
Copy link
Member

@dhardy dhardy commented Feb 9, 2024

Fixes #1307. CC @LikeLakers2.

Renames WeightedErrorWeightError, revises variants and re-exports from rand::seq.

Adjusts WeightError cases: WeightedTreeIndex (NaNs and try_sample @xmakro) and rand::seq::index::sample_weighted (replace panic; catch too-many-zeros).

Splits SliceRandom into multiple traits to solve #1307. I'm not wildly keen on the result but don't currently have a better idea.

@LikeLakers2
Copy link

I took a general look at 06fe3d8 (the commit where you split SliceRandom).

Unless I'm missing something (it's been a while since I touched rand, so I'm going off of what I put in #1307, plus my own intuition), I believe you've solved the issue I had. So thank you.

I'm not wildly keen on the result but don't currently have a better idea.

Personally, I'm a fan of this solution. Not only does it make it possible for non-std collections to implement random functionality, but it makes it as simple as impl-ing one method on one trait.

Still, if you come up with a better idea, don't be afraid to poke me and I'll tell you what I think.

Copy link
Contributor

@TheIronBorn TheIronBorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@dhardy
Copy link
Member Author

dhardy commented Feb 15, 2024

Thanks @TheIronBorn

@dhardy dhardy merged commit dba696e into rust-random:master Feb 15, 2024
dhardy added a commit to dhardy/rand that referenced this pull request Feb 18, 2024
@dhardy dhardy deleted the choose_for_indexed branch July 8, 2024 09:58
cratelyn added a commit to linkerd/linkerd2-proxy that referenced this pull request Jan 28, 2025
cratelyn added a commit to linkerd/linkerd2-proxy that referenced this pull request Jan 28, 2025
cratelyn added a commit to linkerd/linkerd2-proxy that referenced this pull request Jan 28, 2025
supersedes #3569.

this branch updates [`rand`](https://github.com/rust-random/rand) from 0.8.5 to 0.9.0.

- [release notes](https://github.com/rust-random/rand/releases)
- [changelog](https://github.com/rust-random/rand/blob/master/CHANGELOG.md)
- [commits](rust-random/rand@0.8.5...0.9.0)

note the changes to `rand::distr::weighted::Error`'s variants. see
rust-random/rand#1382, and
rust-random/rand#1470. in particular, this change:

https://github.com/rust-random/rand/pull/1382/files#diff-b0eb1b0ef894742b65e07f23af6cbeffae64ec8311adb6ea606603e978023e0cL116-R113

most other changes in this branch relate to the renaming of `thread_rng()` to `rng()`,
and `gen()` to `random()`.

---

* build(deps): bump rand from 0.8.5 to 0.9.0

Bumps [rand](https://github.com/rust-random/rand) from 0.8.5 to 0.9.0.
- [Release notes](https://github.com/rust-random/rand/releases)
- [Changelog](https://github.com/rust-random/rand/blob/master/CHANGELOG.md)
- [Commits](rust-random/rand@0.8.5...0.9.0)

---
updated-dependencies:
- dependency-name: rand
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore(exp-backoff): address `rand` breaking changes

Signed-off-by: katelyn martin <kate@buoyant.io>

* chore(pool/p2c): address `rand` breaking changes

Signed-off-by: katelyn martin <kate@buoyant.io>

* chore(distribute): address `rand` breaking changes

see rust-random/rand#1382.

in particular, this part of the change:

https://github.com/rust-random/rand/pull/1382/files#diff-b0eb1b0ef894742b65e07f23af6cbeffae64ec8311adb6ea606603e978023e0cL116-R113

see also rust-random/rand#1470.

Signed-off-by: katelyn martin <kate@buoyant.io>

* chore(http/route): address `rand` breaking changes

Signed-off-by: katelyn martin <kate@buoyant.io>

* chore(exp-backoff): address `rand` breaking changes

Signed-off-by: katelyn martin <kate@buoyant.io>

* chore(deny.toml): skip previous `rand` dependencies

this addresses some ci errors related to duplicate dependencies:

```
error[duplicate]: found 2 duplicate entries for crate 'getrandom'
   ┌─ /github/workspace/Cargo.lock:75:1
   │
75 │ ╭ getrandom 0.2.15 registry+https://github.com/rust-lang/crates.io-index
76 │ │ getrandom 0.3.1 registry+https://github.com/rust-lang/crates.io-index
   │ ╰─────────────────────────────────────────────────────────────────────┘ lock entries
   │
```

Signed-off-by: katelyn martin <kate@buoyant.io>

* review(distribute): add `use` statement

Signed-off-by: katelyn martin <kate@buoyant.io>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: katelyn martin <kate@buoyant.io>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
benjamin-lieser pushed a commit to benjamin-lieser/rand that referenced this pull request Feb 5, 2025
…om (rust-random#1382)

* Remove deprecated module rand::distributions::weighted
* WeightedTree: return InvalidWeight on not-a-number
* WeightedTree::try_sample return AllWeightsZero given no weights
* Rename WeightedError -> WeightError and revise variants
* Re-export WeightError from rand::seq
* Revise errors of rand::index::sample_weighted
* Split SliceRandom into IndexedRandom, IndexedMutRandom and SliceRandom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants