'Select subset of test cases from all possible combinations

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 :)



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Benjamin Luo