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

Consecutive calls of random returns the same instance #44

Open
zzvara opened this issue Jun 24, 2017 · 9 comments
Open

Consecutive calls of random returns the same instance #44

zzvara opened this issue Jun 24, 2017 · 9 comments
Labels

Comments

@zzvara
Copy link

zzvara commented Jun 24, 2017

Consecutive calls of random returns the same instance. Providing an integer to get multiple random elements will however generate different instances. How to overcome this?
(I'm not familiar with Shapless, just want to have simple instances fast.)

@DanielaSfregola
Copy link
Owner

Hi @zzvara,
this is actually not a Shapeless problem, but it is enforced by design of the library.

See #37 (comment) for an explanation of this issue.

Happy to discuss possible solutions or suggestions on how to improve this, if you have any.

@zzvara
Copy link
Author

zzvara commented Jun 26, 2017 via email

@DanielaSfregola
Copy link
Owner

How would you handle that tests can run in parallel? i.e.: the order in which random is called is not guaranteed...

@zzvara
Copy link
Author

zzvara commented Jun 27, 2017 via email

@DanielaSfregola
Copy link
Owner

Give it a try @zzvara! Please, if it works I'd love to see a PR on this.

Cheers,
D.

alexbalonperin pushed a commit to alexbalonperin/random-data-generator that referenced this issue Mar 16, 2018
alexbalonperin pushed a commit to alexbalonperin/random-data-generator that referenced this issue Mar 16, 2018
alexbalonperin pushed a commit to alexbalonperin/random-data-generator that referenced this issue Mar 16, 2018
alexbalonperin pushed a commit to alexbalonperin/random-data-generator that referenced this issue Mar 16, 2018
@krishna-meduri
Copy link

Hi @zzvara and @DanielaSfregola Why can't we go for "call by name" which makes the body of the method to execute, every time when this method is called? This makes every, consecutive call to random an actual invocation and will always return a new instance (instead of cached results). I am pretty sure that, I am missing some context. If so, please correct me. Thank you.

@DanielaSfregola
Copy link
Owner

Hi @krishna-meduri,
using simply random values will not work: we want the ability to reproduce a "randomly generated session", so that people can debug and fix their tests when a problematic session is found.

In the current implementation, requesting a random value of the same type will provide always the same value because we fix the seed.

I am pretty sure there must be a solution - such as having the idea of the global seed and a local seed that we can combine to obtain different values of the same type.

We "just" need to find a solution that guarantees that a session can be reproduced by fixing the seed independently from the execution order of a test.

@krishna-meduri
Copy link

@DanielaSfregola Got it. Thank you. Will try to see if I could come up with a solution and will update you.

@anton-zen
Copy link

I just use these 2 directly without random-data-generator:

import org.scalacheck.Arbitrary
import org.scalacheck.Gen

https://booksites.artima.com/scalacheck/examples/html/ch06.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants