code: def test_random_seed_setting_for_context():
      seed_to_test = 1234
      num_temp_seeds = 25
      probs = [0.125, 0.25, 0.25, 0.0625, 0.125, 0.1875]
      num_samples = 100000
      dev_type = mx.context.current_context().device_type
      for dtype in ["float16", "float32", "float64"]:
          samples_imp = []
          samples_sym = []
          # Collect random number samples from the generators of all devices, each seeded with the same number.
          for dev_id in range(
              0, mx.device.num_gpus() if dev_type == "gpu" else 1
          ):
              with mx.Context(dev_type, dev_id):
                  ctx = mx.context.current_context()
                  seed = set_seed_variously_for_context(
                      ctx, 1, num_temp_seeds, seed_to_test
                  )
  
                  # Check imperative. `categorical` uses non-parallel rng.
                  rnds = mx.nd.random.categorical(
                      data=mx.nd.array(probs, dtype=dtype),
                      shape=num_samples,
                  )
                  samples_imp.append(rnds.asnumpy())
  
                  # Check symbolic. `categorical` uses non-parallel rng.
                  P = mx.sym.Variable("P")
                  X = mx.sym.random.categorical(
                      data=P, shape=num_samples, get_prob=False
                  )
                  exe = X._bind(
                      ctx, {"P": mx.nd.array(probs, dtype=dtype)}
                  )
                  set_seed_variously_for_context(
                      ctx, seed, num_temp_seeds, seed_to_test
                  )
                  exe.forward()
                  samples_sym.append(exe.outputs[0].asnumpy())
          # The samples should be identical across different gpu devices.
          for i in range(1, len(samples_imp)):
              assert same(samples_imp[i - 1], samples_imp[i])
          for i in range(1, len(samples_sym)):
              assert same(samples_sym[i - 1], samples_sym[i])
  
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 9 for calling a global function with example usage: test_random_seed_setting_for_context() without return types