Have a Strategy that does not uniformly choose bet

2019-08-17 23:47发布

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?

1条回答
等我变得足够好
2楼-- · 2019-08-18 00:26

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.

查看更多
登录 后发表回答