-
Notifications
You must be signed in to change notification settings - Fork 432
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
Revise Rng
methods
#293
Comments
I always though of For such small integers the implementation of Or Because using Examples of what to replace
|
Forgot to say, good overview!
I think it is very useful, for the reason that it makes it easy to use distributions. And I see it as the counterargument against removing
I don't think the reason "this is an actual algorithm and not so directly related to RNGs" is very strong. Especially because I don't see even the possibility of a different algorithm (although we could make it faster by making much better use of the bits generated by the RNG). But making it possible to write I would definitely like to keep If we add some other method to sample from booleans, |
Fair point about I don't think we should support I guess |
One more reason to keep `shuffle` is to discourage people from writing their own, incorrect, implementation. I see far too many bad ones. Giving users a convenient, fast, correct option makes that less likely.
…Sent from my mobile device
On Mar 11, 2018, at 00:23, Diggory Hardy ***@***.***> wrote:
Fair point about gen_weighted_bool; I'm happy to lose that.
I don't think we should support rng.shuffle(slice) and slice.shuffle(rng). If we prefer the latter, we have to add another trait that users have to import.
I guess gen_bool is as good a name as any. We don't have to add this, but the alternative is that users tend to write rng.gen() < p a lot, which is not quite so clear and doesn't let us try to improve precision near 0.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
We could move Generating weighted booleans seems very niche and could be supported more cleanly by distributions, so I thinks it makes sense to remove
Note that it is also possible to use Personally, I prefer |
To put one more idea in the mix: how would we describe the trait? I would describe Would it then make sense to rename |
What about making a trait and module for use with slices? Than you can do both: |
Yes, putting this all in one place makes sense, though I don't know that we need it in |
If we do that and move the sampling to distributions, we could get rid of the the |
In theory yes, but I'm not inclined to remove |
There are two minor issues with renaming Rng → Random:
The idea has some merit, but needs more discussion than as a little question in a vaguely-related issue. If you want to push the idea further create a new issue and try to catch more attention (labels, maybe a reddit post, examples of user code). I kind of like the current approach though because |
You are right. I only thought about the imports that would have to change, but this also impacts things like trait bounds. And there is something to say for a clear 'details' trait name as |
I think this issue is solved? |
Summary:
gen_iter
andgen_ascii_chars
shuffle
,choose
andchoose_mut
: topic of Sequence sampling:seq
,WeightedChoice
dhardy/rand#82gen_weighted_bool
gen_bool
Original post:
Rng
has:fill(dest)
,try_fill(dest)
— will slices/arrays; mostly added to avoid need to useRngCore
for itsfill_bytes
sample(distribution)
— alternative todistribution.sample(rng)
; possibly not very usefulgen()
— sample anything supporting theUniform
distribution; @clarcharr suggested removing this but I don't think that is likelygen_iter()
,gen_ascii_chars()
— deprecatedgen_range(low, high)
— shortcut forRange::sample_single(low, high, rng)
; probably worth keepinggen_weighted_bool(n)
— simple extension ofgen_range()
; likely not used massively but simple and clear, so I don't see a motive to removechoose(slice)
,choose_mut(slice)
— get a ref to a random element; simple and somewhat usefulshuffle(slice)
— shuffling algorithm; since this is an actual algorithm and not so directly related to RNGs it may be better removing fromRng
and adding some shuffle trait instead (allowingslice.shuffle(rng)
)Possible additions:
p(p)
/chance(p)
/gen_bernoulli(p)
— sample a boolean with given chance (i.e. roughlyrng.gen() < p
, but we might implement a distribution with more accurate sampling for smallp
)Summary (suggested changes):
gen_iter
andgen_ascii_chars
are being removedshuffle
may be removedsample
andgen
could be removed, but less likelyThe text was updated successfully, but these errors were encountered: