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

Q: How to choose from a fixed set of random values? #23

Open
dcastro opened this issue Jul 13, 2016 · 0 comments
Open

Q: How to choose from a fixed set of random values? #23

dcastro opened this issue Jul 13, 2016 · 0 comments

Comments

@dcastro
Copy link

dcastro commented Jul 13, 2016

(If this is not the proper channel for questions, please close this and kindly point me to the right channel)

Say I want to generate some value v from a fixed set of random integers. E.g.

case class Person(age: Int)

val personRng = f(Rng.int, Rng.int, Rng.int).map(i => Person(i))

val io = personRng.run

io.unsafePerformIO // prints `Person(10)`
io.unsafePerformIO // prints `Person(19)`
io.unsafePerformIO // prints `Person(10)`
io.unsafePerformIO // prints `Person(19)`
io.unsafePerformIO // prints `Person(77)`
io.unsafePerformIO // prints `Person(19)`
io.unsafePerformIO // prints `Person(77)`

I don't care what the numbers are, but I care that they're always picked from a pool with a fixed size.

I tried the following, which did not produce what I expected:

val personRng = for {
  a <- Rng.int
  b <- Rng.int
  c <- Rng.int
  age <- Rng.oneof(a, b, c)
} yield Person(age)

This seems like it should be easy to achieve, but I can't figure out how.

Thanks in advance.

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

No branches or pull requests

1 participant