Skip to content

Revise Rng methods #293

@dhardy

Description

@dhardy

Summary:


Original post:

Rng has:

  • fill(dest), try_fill(dest) — will slices/arrays; mostly added to avoid need to use RngCore for its fill_bytes
  • sample(distribution) — alternative to distribution.sample(rng); possibly not very useful
  • gen() — sample anything supporting the Uniform distribution; @clarcharr suggested removing this but I don't think that is likely
  • gen_iter(), gen_ascii_chars() — deprecated
  • gen_range(low, high) — shortcut for Range::sample_single(low, high, rng); probably worth keeping
  • gen_weighted_bool(n) — simple extension of gen_range(); likely not used massively but simple and clear, so I don't see a motive to remove
  • choose(slice), choose_mut(slice) — get a ref to a random element; simple and somewhat useful
  • shuffle(slice) — shuffling algorithm; since this is an actual algorithm and not so directly related to RNGs it may be better removing from Rng and adding some shuffle trait instead (allowing slice.shuffle(rng))

Possible additions:

  • p(p) / chance(p) / gen_bernoulli(p) — sample a boolean with given chance (i.e. roughly rng.gen() < p, but we might implement a distribution with more accurate sampling for small p)

Summary (suggested changes):

  • gen_iter and gen_ascii_chars are being removed
  • shuffle may be removed
  • sample and gen could be removed, but less likely
  • a method to sample booleans may be added

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-APIBreakage: APIF-new-intFunctionality: new, within Rand

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions