code: def test_zipfian_generator():
      # dummy true classes
      num_true = 5
      num_sampled = 1000
      range_max = 20
  
      def compute_expected_prob():
          # P(class) = (log(class + 2) - log(class + 1)) / log(range_max + 1)
          classes = mx.nd.arange(0, range_max)
          expected_counts = (
              (classes + 2).log() - (classes + 1).log()
          ) / np.log(range_max + 1)
          return expected_counts
  
      exp_cnt = compute_expected_prob() * num_sampled
  
      # test ndarray
      true_classes = mx.nd.random.uniform(
          0, range_max, shape=(num_true,)
      ).astype("int32")
      (
          sampled_classes,
          exp_cnt_true,
          exp_cnt_sampled,
      ) = mx.nd.contrib.rand_zipfian(
          true_classes, num_sampled, range_max
      )
      assert_almost_equal(
          exp_cnt_sampled,
          exp_cnt[sampled_classes],
          rtol=1e-1,
          atol=1e-2,
      )
      assert_almost_equal(
          exp_cnt_true, exp_cnt[true_classes], rtol=1e-1, atol=1e-2
      )
  
      # test symbol
      true_classes_var = mx.sym.var("true_classes")
      outputs = mx.sym.contrib.rand_zipfian(
          true_classes_var, num_sampled, range_max
      )
      outputs = mx.sym.Group(outputs)
      executor = outputs._bind(
          mx.context.current_context(), {"true_classes": true_classes}
      )
      executor.forward()
      sampled_classes, exp_cnt_true, exp_cnt_sampled = executor.outputs
      assert_almost_equal(
          exp_cnt_sampled,
          exp_cnt[sampled_classes],
          rtol=1e-1,
          atol=1e-2,
      )
      assert_almost_equal(
          exp_cnt_true, exp_cnt[true_classes], rtol=1e-1, atol=1e-2
      )
  
imports: import os
  import math
  import itertools
  import mxnet
  from mxnet.test_utils import verify_generator, gen_buckets_probs_with_ppf, assert_almost_equal
  import numpy
  import random
  from common import retry, random_seed
  import scipy.stats
  import unittest
  import pytest
  from mxnet.test_utils import *
  from mxnet.base import MXNetError
  from common import assertRaises
label_desc: Use image node_id 24 for calling a global function with example usage: test_zipfian_generator() and returns: expected_counts