code: def weighted_sample(self, dim=None):
      """
      Samples a single value across dimension `dim` with weights corresponding
      to the values in `self`
  
      Returns the sample and the one-hot index of the sample.
  
      Examples::
  
          >>> encrypted_tensor = MPCTensor(torch.tensor([1., 6.]))
          >>> index = encrypted_tensor.weighted_sample().get_plain_text()
          # With 1 / 7 probability
          (torch.tensor([1., 0.]), torch.tensor([1., 0.]))
  
          # With 6 / 7 probability
          (torch.tensor([0., 6.]), torch.tensor([0., 1.]))
      """
      indices = self.weighted_index(dim)
      sample = self.mul(indices).sum(dim)
      return sample, indices
  
imports: import crypten
  import torch
label_desc: Use image node_id 4 for calling a global function with example usage: weighted_sample(dim) and returns: sample,  indices