code: def sample_from_single_dataset(
      dataset_for_sample,
      source,
      utterance_num,
      user_id_to_start,
      random_int_for_sample,
  ):
      utterance_cnt = 0
      user_id = user_id_to_start
      output_data = []
      while utterance_cnt < utterance_num:
          #     draw a number for user id
          current_user_utterance_num = int(
              random.choice(random_int_for_sample)
          )
          if current_user_utterance_num + utterance_cnt > utterance_num:
              current_user_utterance_num = utterance_num - utterance_cnt
          utterance_cnt += current_user_utterance_num
          #     sample with replacement
          samples = copy.deepcopy(
              random.choices(
                  dataset_for_sample, k=current_user_utterance_num
              )
          )
          for each_sample in samples:
              #         adding user id
              each_sample["user_id"] = user_id
              each_sample["source"] = source
              each_sample["gold_labels"] = copy.deepcopy(
                  each_sample["labels"]
              )
              output_data.append(each_sample)
          user_id += 1
      assert len(output_data) == utterance_num
      return output_data, user_id
  
file_path: ParlAI/parlai/tasks/safety_mix/build.py
imports: import copy
  import hashlib
  import json
  import os
  import random
  import numpy
  import parlai.core.build_data
  import parlai.utils.logging
  from parlai.core.build_data import DownloadableFile
label_desc: Use image node_id 3 for calling a global function with example usage: sample_from_single_dataset(dataset_for_sample, source, utterance_num, user_id_to_start, random_int_for_sample) and returns: output_data,  user_id