import random


def _get_samples(key, rate):
  """Maps a sampling rate into an integer sample count deterministically.

  Args:
    key: Key to use for hashing function.
    rate: Sample rate.

  Returns:
    sample_count. If `rate` is an integer, the function returns `rate`. For the
      decimal part we sample a random number from [0, 1) and add one if sampled]
      float is below the mantissa.
  """
  int_rate = int(rate)
  if int_rate == rate:  # Not really needed but adding to be safe.
    return int_rate
  decimal_part = rate - int_rate
  return int_rate + int(random.Random(key).random() < decimal_part)