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

Add .choices() method to the Slice distribution #1402

Merged
merged 6 commits into from
Mar 7, 2024

Conversation

JustusFluegel
Copy link
Contributor

@JustusFluegel JustusFluegel commented Mar 3, 2024

  • Added a CHANGELOG.md entry

Summary

Add a .choices() -> NonZeroUsize method to the slices distribution

Motivation

In one of my projects we use a Slice Distribution for the input of a constructor for a type which needs to generate some element of that slice & at the same time a boolean for another variable with the same probability of each element in the Distribution occurring. A simple 1 / distr.choices() would help us a lot in that regards.

Details

Adds the Slices::choices() - NonZeroUsize method, which returns the count of different choices in the input vector (counting duplicates in that vector as well)

Signed-off-by: Justus Fluegel <justusfluegel@gmail.com>
Signed-off-by: Justus Fluegel <justusfluegel@gmail.com>
@JustusFluegel
Copy link
Contributor Author

I am not quite sure if that changelog format I am using here is correct so I would appreciate someone looking over that and giving me a short reply :)

src/distributions/slice.rs Outdated Show resolved Hide resolved
src/distributions/slice.rs Outdated Show resolved Hide resolved
Signed-off-by: Justus Fluegel <justusfluegel@gmail.com>
@JustusFluegel
Copy link
Contributor Author

Sorry I kinda messed up my commits here, wanted to keep a clean history so force-pushed to my branch ( shouldn't really matter on your end either way )

@dhardy
Copy link
Member

dhardy commented Mar 4, 2024

No worries about commit history; we squash in this repo. (Personally I still force-push often enough.)

…call time

Signed-off-by: Justus Fluegel <justusfluegel@gmail.com>
Signed-off-by: Justus Fluegel <justusfluegel@gmail.com>
Signed-off-by: Justus Fluegel <justusfluegel@gmail.com>
Copy link
Member

@dhardy dhardy left a comment

Choose a reason for hiding this comment

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

A little unorthodox, but seems fine to me. 👍

Copy link
Member

@MichaelOwenDyer MichaelOwenDyer 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

dhardy commented Mar 7, 2024

CI failure is a false positive from the new non_local_definitions lint; leave for now.

@dhardy dhardy merged commit 7ed92ee into rust-random:master Mar 7, 2024
10 of 12 checks passed
@JustusFluegel
Copy link
Contributor Author

CI failure is a false positive from the new non_local_definitions lint; leave for now.

yep I figured :)

@JustusFluegel
Copy link
Contributor Author

Is there some information on the release cycle of rand somewhere ( Is there a date when this will be in alpha / stable )? Don't want to push you to release something, just some information on when I should check back here would be nice :)

@dhardy
Copy link
Member

dhardy commented Mar 17, 2024

There's a tracking issue for 0.9. We're a little slow making releases, but I'll push out a second alpha soon.

@JustusFluegel
Copy link
Contributor Author

thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants