code: def testSamplingWithSeedDoesNotAffectFutureCalls(self):
      # Setting the seed here will set a deterministic random value r, which will
      # be used when sampling from the tree. Since it is scalled up by the total
      # sum value of the tree, M, we can see that r' * M + m = M, where:
      #   - M  = total sum value of the tree (total_value)
      #   - m  = value of node 3 (max_value)
      #   - r' = r + delta
      # We can then solve for M: M = m / (1 - r'), and we can set the value of the
      # node 2 to r' * M + delta, which will guarantee that
      # r * M < r' * M + delta, thereby guaranteeing that node 2 will always get
      # picked.
      seed = 1
      random.seed(seed)
      deterministic_random_value = random.random()
      max_value = 100
      delta = 0.01
      total_value = max_value / (1 - deterministic_random_value - delta)
      min_value = deterministic_random_value * total_value + delta
      self._tree.set(node_index=2, value=min_value)
      self._tree.set(node_index=3, value=max_value)
      for _ in range(10000):
          random.seed(seed)
          self.assertEqual(self._tree.sample(), 2)
      # The above loop demonstrated that there is 0 probability that node 3 gets
      # selected. The loop below demonstrates that this probability is no longer
      # 0 when the seed is not set explicitly. There is a very low probability
      # that node 2 gets selected, but to avoid flakiness, we simply assert that
      # node 3 gets selected most of the time.
      counts = {2: 0, 3: 0}
      for _ in range(10000):
          counts[self._tree.sample()] += 1
      self.assertLess(counts[2], counts[3])
  
imports: import random
  import unittest
  from reagent.replay_memory import sum_tree
label_desc: Use image node_id 13 for calling the SumTreeTest obj's underlying member method code with example usage: obj.testSamplingWithSeedDoesNotAffectFutureCalls() without return types