0

I'd like to create a strategy C that, 90% of the time chooses strategy A, and 10% of the time chooses strategy B.

The random python library does not work even if I seed it since each time the strategy produces values, it generates the same value from random.

I looked at the implementation for OneOfStrategy and they use i = cu.integer_range(data, 0, n - 1) to randomly generate a number

cu is from the internals import hypothesis.internal.conjecture.utils as cu

Would it be fine for my strategy to use cu.integer_range or is there another implementation?

Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123
  • 1
    Welcome to Stack Overflow! Can you show us what you've got so far? Check out [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) so that we have enough information to properly help you. – Jaquez Apr 14 '18 at 02:45

1 Answers1

3

Hypothesis does not allow users to control the probability of various choices within a strategy. You should not use undocumented interfaces either - hypothesis.internal is for internal use only and could break at any time!

I strongly recommend using C = st.one_of(A, B) and trusting Hypothesis with the details.

Zac Hatfield-Dodds
  • 2,455
  • 6
  • 19
  • What i'm using hypothesis for is to generate RPC against a server. I disabled the use_coverage setting because it would have done coverage on the client (which I'm not interested in since it is a very simiple client). My goal with hypothesis is to generate variety of traffic against the server. I did `choice = data.draw(st.sampled_from(range(1, 10)))` since sampled_from is suppose to be uniform. Depending on the value of choice, I choose a strategy. Would this work? If not, what do you suggest instead for my use case – curious_george Apr 16 '18 at 17:16
  • Sampling is **not** supposed to be uniform; Hypothesis never gives you a specific distribution. As above, "I strongly recommend using [`C = st.one_of(A, B)`"!](https://hypothesis.readthedocs.io/en/latest/data.html#hypothesis.strategies.one_of) – Zac Hatfield-Dodds Apr 17 '18 at 07:08