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

api: add Gen::set_size and Gen::from_seed #278

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jakoschiko
Copy link

The seed still can't be set by QuickCheck users, but the new Gen
constructor is useful for other crates that use QuickCheck only for
its Arbitrary trait.

Closes #277

The seed still can't be set by QuickCheck users, but the new Gen
constructor is useful for other crates that use QuickCheck only for
its Arbitrary trait.

Closes BurntSushi#277
@jakoschiko
Copy link
Author

@BurntSushi

Some questions:

  • I called the new constructor Gen::from_seed. Is that okay? Or maybe Gen::from_seed_u64?
  • You regret the current constructor Gen::new because it takes a size parameter. Should I add a Default implementation for Gen with random seed and default size?
  • Are you sure that you want a Gen::set_size? Arbitrary::arbitrary takes a &mut Gen and this function makes it very easy to change not only the own local size, but also the size of the Arbitrary::arbitrary caller. Maybe we should provide a Gen::with_size that returns a copy.

@audunska
Copy link

audunska commented Mar 26, 2021

Just my thoughts here, but Gen::with_size seems reasonable here. Maybe even one that takes a closure? I.e., to generate arbitrary vec's with a size parameter of 10:
gen.with_size(10, Vec::arbitrary)

It would be implemented something like

impl Gen {
  pub fn with_size<T>(&mut self, size: usize, f: impl FnOnce(&mut Gen) -> T) -> T {
    let old_size = self.size;
    self.size = size;
    let res = f(self);
    self.size = old_size;
    res
  }
}

@aakoshh
Copy link

aakoshh commented Jan 18, 2023

What's the status of this PR? It would be super useful to have a seedable Gen.

@JarredAllen
Copy link

^ I am also interested in this.

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.

Gen from seed
4 participants