code: def generate_random_ring_element(
      ctx, size, ring_size=(2**64), generator=None, **kwargs
  ):
      """Helper function to generate a random number from a signed ring"""
      device = kwargs.get("device", torch.device("cpu"))
      device = torch.device("cpu") if device is None else device
      device = (
          torch.device(device) if isinstance(device, str) else device
      )
      if generator is None:
          generator = mpc.generators["local"][device]
      # TODO (brianknott): Check whether this RNG contains the full range we want.
      if isinstance(size, _ShardingShapes):
          shape_and_states = [
              (shape, _next_seed_from_generator(generator))
              for shape in size.shapes
          ]
          rand_element = DTensor.from_sharding_table(
              data=ctx.computing.parallelize(
                  shape_and_states, include_key=False
              ).mapValues(
                  lambda x: generate_random_ring_element_by_seed(
                      x[0], seed=x[1], device=device
                  )
              ),
              shapes=size.shapes,
              axis=size.axis,
              dtype=torch.long,
              device=device,
          )
          return rand_element
  
      else:
          rand_element = torch.randint(
              -(ring_size // 2),
              (ring_size - 1) // 2,
              size,
              generator=generator,
              dtype=torch.long,
              **kwargs,
          )
          if rand_element.is_cuda:
              return CUDALongTensor(rand_element)
          return rand_element
  
file_path: FATE/python/fate/arch/protocol/mpc/common/rng.py
imports: import torch
  from fate.arch.protocol import mpc
  from fate.arch.protocol.mpc.cuda import CUDALongTensor
  from fate.arch.tensor.distributed._tensor import _ShardingShapes, DTensor
label_desc: Use image node_id 2 for calling a global function with example usage: generate_random_ring_element(ctx, size, ring_size, generator) and returns: rand_element, rand_element, CUDALongTensor