code: def test_random_sample(ray_start_regular_shared):
      import math
  
      def ensure_sample_size_close(dataset, sample_percent=0.5):
          r1 = ds.random_sample(sample_percent)
          assert math.isclose(
              r1.count(),
              int(ds.count() * sample_percent),
              rel_tol=2,
              abs_tol=2,
          )
  
      ds = ray.data.range(10, parallelism=2)
      ensure_sample_size_close(ds)
  
      ds = ray.data.range(10, parallelism=2)
      ensure_sample_size_close(ds)
  
      ds = ray.data.range_tensor(5, parallelism=2, shape=(2, 2))
      ensure_sample_size_close(ds)
  
      # imbalanced datasets
      ds1 = ray.data.range(1, parallelism=1)
      ds2 = ray.data.range(2, parallelism=1)
      ds3 = ray.data.range(3, parallelism=1)
      # noinspection PyTypeChecker
      ds = ds1.union(ds2).union(ds3)
      ensure_sample_size_close(ds)
      # Small datasets
      ds1 = ray.data.range(5, parallelism=5)
      ensure_sample_size_close(ds1)
  
imports: import itertools
  import math
  import os
  import signal
  import threading
  import time
  from typing import Iterator
  import numpy
  import pandas
  import pyarrow
  import pyarrow.parquet
  import pytest
  import ray
  from ray._private.test_utils import wait_for_condition
  from ray.data.block import BlockAccessor
  from ray.data.context import DataContext
  from ray.data.tests.conftest import *
  from ray.data.tests.util import column_udf, column_udf_class, extract_values
  from ray.tests.conftest import *
label_desc: Use image node_id 23 for calling a global function with example usage: test_random_sample(ray_start_regular_shared) without return types