0

Let's say I'm writing a lifespan prediction calculator that takes in ~40 inputs:

sex = ['Male', 'Female']
smoking_status = [True, False]
...

Eventually, there will be trillions of possible test cases that can be exposed using itertools but these are computed by gradually adjusting each field from left to right:

for test_case in itertools.product(sex, smoking_status):
    assert(myfunc(test_case) = trueval(test_case)

Output (not randomized):

['Male', True]
['Male', False]
['Female', True]
['Female', False]

How can I randomly select N=1000 test cases from all possible combinations?

Edit: Constraint #1: As I am concerned over the health and wellbeing of my laptop, I am adding a constraint where I cannot generate a list containing hundreds of trillions of elements and then randomly select a subset of it :)

Benjamin Luo
  • 131
  • 8
  • This is a follow up question to https://stackoverflow.com/questions/71401307/python-finding-inputs-of-every-possible-test-case/71401561?noredirect=1#comment126251681_71401561 which calculated ALL possible combinations rather than a random subset – Benjamin Luo Mar 10 '22 at 18:47
  • Does this answer your question? [Select 50 items from list at random](https://stackoverflow.com/questions/15511349/select-50-items-from-list-at-random) – mkrieger1 Mar 10 '22 at 19:03
  • @mkrieger1 Thanks for researching. That question has a list that has already been generated, but I want to avoid generating a list as it would have trillions of indexes in my case – Benjamin Luo Mar 10 '22 at 19:05
  • You should clarify that in your question. – mkrieger1 Mar 10 '22 at 19:07

1 Answers1

0

My solution was eventually storing all variables in a dictionary where keys are the variable names and values are a list of all possible values

I then looped through each item, (Pseudo-code:) [k:v[randint(0, len(v))] for k, v in mydict.items()] and used the random integer function to randomly choose an index

NOTE: This does not account for overlap; it is possible to produce 2 identical test cases but it's acceptable for me as there are trillions of possible test cases

Benjamin Luo
  • 131
  • 8