code: def exact_sampler(scale, num_samples, seed=EXACT_SAMPLER_SEED):
      """Implementation of the exact discrete gaussian distribution sampler.
  
      Source: https://arxiv.org/pdf/2004.00010.pdf.
  
      Args:
        scale: The scale of the discrete Gaussian.
        num_samples: The number of samples to generate.
        seed: The seed for the random number generator to reproduce samples.
  
      Returns:
        A numpy array of discrete Gaussian samples.
      """
  
      def randrange(a, rng):
          return rng.randrange(a)
  
      def bern_em1(rng):
          """Sample from Bernoulli(exp(-1))."""
          k = 2
          while True:
              if randrange(k, rng) == 0:  # if Bernoulli(1/k)==1
                  k = k + 1
              else:
                  return k % 2
  
      def bern_emab1(a, b, rng):
          """Sample from Bernoulli(exp(-a/b)), assuming 0 <= a <= b."""
          assert isinstance(a, int)
          assert isinstance(b, int)
          assert 0 <= a <= b
          k = 1
          while True:
              if (
                  randrange(b, rng) < a and randrange(k, rng) == 0
              ):  # if Bern(a/b/k)==1
                  k = k + 1
              else:
                  return k % 2
  
      def bern_emab(a, b, rng):
          """Sample from Bernoulli(exp(-a/b)), allowing a > b."""
          while a > b:
              if bern_em1(rng) == 0:
                  return 0
              a = a - b
          return bern_emab1(a, b, rng)
  
      def geometric(t, rng):
          """Sample from geometric(1-exp(-1/t))."""
          assert isinstance(t, int)
          assert t > 0
          while True:
              u = randrange(t, rng)
              if bern_emab1(u, t, rng) == 1:
                  while bern_em1(rng) == 1:
                      u = u + t
                  return u
  
      def dlap(t, rng):
          """Sample from discrete Laplace with scale t.
  
          Pr[x] = exp(-|x|/t) * (exp(1/t)-1)/(exp(1/t)+1). Supported on integers.
  
          Args:
            t: The scale.
            rng: The random number generator.
  
          Returns:
            A discrete Laplace sample.
          """
          assert isinstance(t, int)
          assert t > 0
          while True:
              u = geometric(t, rng)
              b = randrange(2, rng)
              if b == 1:
                  return u
              elif u > 0:
                  return -u
  
      def floorsqrt(x):
          """Compute floor(sqrt(x)) exactly."""
          assert x >= 0
          a = 0  # maintain a^2<=x.
          b = 1  # maintain b^2>x.
          while b * b <= x:
              b = 2 * b
          # Do binary search.
          while a + 1 < b:
              c = (a + b) // 2
              if c * c <= x:
                  a = c
              else:
                  b = c
          return a
  
      def dgauss(ss, num, rng):
          """Sample from discrete Gaussian.
  
          Args:
            ss: Variance proxy, squared scale, sigma^2.
            num: The number of samples to generate.
            rng: The random number generator.
  
          Returns:
            A list of discrete Gaussian samples.
          """
          ss = fractions.Fraction(
              ss
          )  # cast to rational for exact arithmetic
          assert ss > 0
          t = floorsqrt(ss) + 1
          results = []
          trials = 0
          while len(results) < num:
              trials = trials + 1
              y = dlap(t, rng)
              z = (abs(y) - ss / t) ** 2 / (2 * ss)
              if bern_emab(z.numerator, z.denominator, rng) == 1:
                  results.append(y)
          return results, t, trials
  
      rng = random.Random(seed)
      return np.array(dgauss(scale * scale, num_samples, rng)[0])
  
imports: import collections
  import fractions
  import math
  import random
  from absl.testing import parameterized
  import numpy
  import tensorflow
  from tensorflow_privacy.privacy.dp_query import discrete_gaussian_utils
label_desc: Use image node_id 1 for calling a global function with example usage: exact_sampler(scale, num_samples, seed) and returns: np, rng, bern_emab1, a, results,  t,  trials, unknown, unknown, int, u, u, unknown