code: def test_random_search(tmp_path):
      # TensorFlow model building and execution is not thread-safe.
      num_workers = 1
  
      x = np.random.uniform(-1, 1, size=(2, 5))
      y = np.ones((2,))
  
      def _test_random_search():
          def build_model(hp):
              model = keras.Sequential()
              model.add(
                  keras.layers.Dense(
                      hp.Int("num_units", 1, 3), input_shape=(5,)
                  )
              )
              model.add(keras.layers.Dense(1))
              model.compile(loss="mse")
              return model
  
          tuner = keras_tuner.tuners.RandomSearch(
              hypermodel=build_model,
              objective="val_loss",
              max_trials=10,
              directory=tmp_path,
          )
          tuner.search(
              x,
              y,
              validation_data=(x, y),
              epochs=1,
              batch_size=2,
              verbose=0,
          )
  
          # Suppress warnings about optimizer state not being restored by
          # tf.keras.
  
          if dist_utils.is_chief_oracle():
              trials = tuner.oracle.get_best_trials(2)
              assert trials[0].score <= trials[1].score
  
              models = tuner.get_best_models(2)
              assert models[0].evaluate(x, y, verbose=0) <= models[
                  1
              ].evaluate(x, y, verbose=0)
  
      mock_distribute.mock_distribute(
          _test_random_search, num_workers, wait_for_chief=True
      )
  
imports: import copy
  import os
  from unittest import mock
  import numpy
  import portpicker
  import pytest
  import keras_tuner
  from keras_tuner.backend import keras
  from keras_tuner.distribute import oracle_client
  from keras_tuner.distribute import utils
  from keras_tuner.engine import hyperparameters
  from keras_tuner.test_utils import mock_distribute
  from keras_tuner.tuners import randomsearch
label_desc: Use image node_id 2 for calling a global function with example usage: test_random_search(tmp_path) and returns: model