code: def rand_init_delta(delta, x, ord, eps, clip_min, clip_max):
      # TODO: Currently only considered one way of "uniform" sampling
      # for Linf, there are 3 ways:
      #   1) true uniform sampling by first calculate the rectangle then sample
      #   2) uniform in eps box then truncate using data domain (implemented)
      #   3) uniform sample in data domain then truncate with eps box
      # for L2, true uniform sampling is hard, since it requires uniform sampling
      #   inside a intersection of cube and ball, so there are 2 ways:
      #   1) uniform sample in the data domain, then truncate using the L2 ball
      #       (implemented)
      #   2) uniform sample in the L2 ball, then truncate using the data domain
      # for L1: uniform l1 ball init, then truncate using the data domain
  
      if isinstance(eps, torch.Tensor):
          assert len(eps) == len(delta)
  
      if ord == np.inf:
          delta.data.uniform_(-1, 1)
          delta.data = batch_multiply(eps, delta.data)
      elif ord == 2:
          delta.data.uniform_(clip_min, clip_max)
          delta.data = delta.data - x
          delta.data = clamp_by_pnorm(delta.data, ord, eps)
      elif ord == 1:
          ini = laplace.Laplace(
              loc=delta.new_tensor(0), scale=delta.new_tensor(1)
          )
          delta.data = ini.sample(delta.data.shape)
          delta.data = normalize_by_pnorm(delta.data, p=1)
          ray = uniform.Uniform(0, eps).sample()
          delta.data *= ray
          delta.data = (
              clamp(x.data + delta.data, clip_min, clip_max) - x.data
          )
      else:
          error = "Only ord = inf, ord = 1 and ord = 2 have been implemented"
          raise NotImplementedError(error)
  
      delta.data = clamp(x + delta.data, min=clip_min, max=clip_max) - x
      return delta.data
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  import collections
  import numpy
  import torch
  from torch.distributions import laplace
  from torch.distributions import uniform
  from torch.nn.modules.loss import _Loss
  from advertorch.utils import clamp
  from advertorch.utils import clamp_by_pnorm
  from advertorch.utils import batch_multiply
  from advertorch.utils import normalize_by_pnorm
  from advertorch.utils import predict_from_logits
  from advertorch.loss import ZeroOneLoss
  from advertorch.attacks import Attack, LabelMixin
label_desc: Use image node_id 2 for calling a global function with example usage: rand_init_delta(delta, x, ord, eps, clip_min, clip_max) and returns: delta