title: How to validate a unit test with random values
body: <p>How to validate a unit test with random values?
  I need guarantee that <code>gen_age</code> returns an integer between 15 and 99, but this code is not correct.</p>
  
  <pre><code>import random
  import unittest
  
  
  def gen_age():
      # generate integer between 15 and 99
      return random.randint(15, 99)
  
  
  class AgeTest(unittest.TestCase):
  
      def setUp(self):
          self.a = gen_age()
  
      def test_choice(self):
          element = random.choice(self.a)
          self.assertTrue(element in self.a)
  
      def test_sample(self):
          for element in random.sample(self.a, 98):
              self.assertTrue(element in self.a)
  
  if __name__ == '__main__':
      unittest.main()
  </code></pre>