code: def random_rollout_subsequences(rollouts, num_subsequences, subsequence_length):
    
    def choose_subsequence():
      # TODO(koz4k): Weigh rollouts by their lengths so sampling is uniform over
      # frames and not rollouts.
      rollout = random.choice(rollouts)
      try:
        from_index = random.randrange(len(rollout) - subsequence_length + 1)
      except ValueError:
        # Rollout too short; repeat.
        return choose_subsequence()
      return rollout[from_index:(from_index + subsequence_length)]
  
    return [choose_subsequence() for _ in range(num_subsequences)]
docs: Chooses a random frame sequence of given length from a set of rollouts.