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

Gen from seed #277

Open
jakoschiko opened this issue Feb 8, 2021 · 8 comments · Fixed by parallelsystems/quickcheck#1 · May be fixed by #278
Open

Gen from seed #277

jakoschiko opened this issue Feb 8, 2021 · 8 comments · Fixed by parallelsystems/quickcheck#1 · May be fixed by #278

Comments

@jakoschiko
Copy link

Many crates implement quickcheck::Arbitrary and I was very happy that I could use these implementations in dicetest by implementing quickcheck::Gen. Unfortunately I can't do this anymore since quickcheck 1.0.

Would it be possible to provide a function that creates a Gen from a seed? Something like that:

impl Gen {
    pub fn from_seed(seed: u64, size: usize) -> Gen {
        Gen { rng: rand::rngs::SmallRng::seed_from_u64(seed), size: size }
    }
}
@BurntSushi
Copy link
Owner

That seems sensible to me. I think we should leave off the size parameter perhaps though. I regret that Gen's constructor has it instead of providing a set_size method. So we'll want that when this new constructor is added.

@jakoschiko
Copy link
Author

Can I help by creating a PR?

@BurntSushi
Copy link
Owner

BurntSushi commented Feb 8, 2021 via email

@jakoschiko
Copy link
Author

I'm in no hurry, I'll do it within the next days.

jakoschiko added a commit to jakoschiko/quickcheck that referenced this issue Feb 9, 2021
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 jakoschiko linked a pull request Feb 9, 2021 that will close this issue
@ggreif
Copy link

ggreif commented Feb 9, 2021

May I suggest from_rng(rng) too? @jakoschiko
I have a supplied random gen from the environment that I have to use.
I tried

    Gen {
	rng: SmallRng::from_rng(rng).unwrap(),
	size: 42,
    }

but got

183 |     rng: SmallRng::from_rng(rng).unwrap(),
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ private field

Maybe just making both fields pub would work? Of course that depends on how settled Gen is...

@BurntSushi
Copy link
Owner

No. Because that makes rand_core a public dependency.

@jakoschiko
Copy link
Author

@ggreif
rand_core was recently removed from the interface, see #265. I didn't want to discuss this in this issue, I just wanted a replacement. If elegance doesn't matter, you could generate an u64 using rng and pass it to Gen::from_seed. I think SmallRng::from_rng does something similar, but with more bytes.

@ggreif
Copy link

ggreif commented Feb 9, 2021

Great, a u64 seed is perfectly adequate for my purposes. I am happy without from_rng.

cloudhead pushed a commit to cloudhead/qcheck that referenced this issue Dec 3, 2022
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants