Skip to content

Optimise Rng::gen on arrays? #269

@dhardy

Description

@dhardy

I noticed that Rng::gen and Rng::fill don't do the same thing on arrays and have different results when the element size is small:

  • rng.gen() essentially does [rng.gen(), rng.gen(), ..., rng.gen()]
  • rng.fill(&mut buf) casts buf to &mut [u8] then uses RngCore::fill_bytes — more efficient, and only implemented for integer arrays/slices

We likely want to keep the current behaviour for rng.gen() when the element type is f32/f64/complex types, but for integer types can we optimise to use fill_bytes?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions