rust-fuzz / rust-fuzz/arbitrary

Best way to generate float values in range

Open
#77 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Rust
Stars
880
Forks
93
PR merge metrics
No merged PRs in 30d

Description

Hi folks, in https://github.com/technocreatives/dbc-codegen/issues/12 we're generating implementations of Arbitrary for structs where we know some values have to be in a specific range. For ints, this is not a problem as we just use Unstructured::int_in_range, but I'm unsure how to proceed for floats. (We currently just go with always setting the float field to the lower bound.)

My initial idea was to keep generating floats until we get one in ourr range, but that seems awfully slow. Is there a good strategy for generating floats that are in a specific range? Anything I should look up? All I can find assumes an existing random number library is in place… which I'm hesitant to add just for this.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked issue and the existing Unstructured::int_in_range approach to understand how bounded integers are generated. Review the seven-comment discussion for an agreed strategy and constraints around adding a random-number dependency. Done means the project has a decided, tested way to generate float values within requested bounds.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
testing-qa
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.