Random search

On this page 7

Random search is a derivative-free optimization method that evaluates candidate solutions drawn at random from a defined search space and keeps the best one found. In machine learning and optimization for artificial intelligence, the term most often refers to random hyperparameter search, in which each trial trains a model with a randomly sampled configuration and scores it on validation data.

The method became a standard baseline after research showed that, for a fixed budget of trials, random sampling usually finds better configurations than grid search. The reason is that most models depend strongly on only a few hyperparameters, and random sampling explores many more distinct values of those important dimensions.

How random search explores a search space

Random search works by repeating three steps: sample a configuration, evaluate the objective function, and record the result. The process stops when the trial budget, time limit or compute allowance is exhausted, and the configuration with the best validation score is returned.

The engineer defines a search space with a distribution for every parameter. Continuous parameters such as the learning rate are usually sampled on a logarithmic scale, integer parameters such as the number of layers use a uniform integer range, and categorical parameters such as the optimizer type are drawn from a list. Because trials are independent of each other, the method is embarrassingly parallel: a hundred workers can evaluate a hundred trials at once without coordination.

The table below summarizes typical choices of sampling distribution for common hyperparameters.

HyperparameterTypical rangeSampling distribution
Learning rate1e-5 to 1e-1Log-uniform
Weight decay1e-6 to 1e-2Log-uniform
Dropout rate0.0 to 0.5Uniform
Batch size16 to 512Discrete powers of two
Number of layers2 to 12Uniform integer
OptimizerSGD, Adam, AdamWCategorical
Typical sampling distributions in hyperparameter search

Why random search beats grid search on most problems

The central argument concerns low effective dimensionality. If a model has five hyperparameters but only two strongly affect accuracy, a grid of 3 values per parameter spends 243 trials while testing only 3 distinct values of each important parameter. The same 243 random trials test 243 distinct values of every parameter, so the important dimensions are covered far more densely.

A useful probabilistic result follows from independence. If the top 5 percent of the search space counts as a good region, then 60 random trials give roughly a 95 percent probability of at least one trial landing there, regardless of how many dimensions the space has. This bound explains why random search is a dependable default when the number of trials is modest.

The comparison below places random search next to the neighboring methods of the topic.

MethodHow candidates are chosenMain strengthMain weakness
Grid searchEvery point of a fixed latticeExhaustive and reproducibleCost grows exponentially with dimensions
Random searchIndependent random drawsSimple, parallel, robustIgnores results of earlier trials
Bayesian optimizationSurrogate model and acquisition functionSample-efficient for costly trialsSequential and harder to scale
HyperbandRandom draws with early stoppingSaves compute on weak trialsNeeds a meaningful partial budget
Tree-structured Parzen estimatorDensity models of good and bad trialsHandles conditional spaces wellNeeds warm-up trials
Random search compared with related search strategies

Several variants keep the core idea of random sampling while improving coverage or efficiency. The classic form in numerical optimization, sometimes called pure random search, samples globally; local random search instead perturbs the current best point and moves when the perturbation improves the objective, which makes it a simple relative of hill climbing.

  • Quasi-random sampling uses low-discrepancy sequences such as Sobol or Halton to spread points more evenly than independent draws.
  • Latin hypercube sampling ensures that each parameter range is divided into equal strata and every stratum is sampled once.
  • Successive halving and Hyperband start many random trials with a small budget and give more resources only to the best performers.
  • Adaptive step-size random search shrinks or enlarges the perturbation radius depending on recent success.

Designing a random search experiment

Most of the quality of random search depends on the design of the search space, not on the sampler. Ranges that are too wide waste trials on obviously poor regions, while ranges that are too narrow may exclude the optimum. A sensible practice is to run a short exploratory round, inspect where good trials cluster, and then narrow the ranges for a second round.

The decision table below links common situations to a recommended approach.

SituationRecommended approachReason
Cheap trials, many workersPlain random searchFull parallelism outweighs sample efficiency
Expensive trials, few workersBayesian optimizationEach trial should be chosen carefully
Training curves available earlyHyperband with random samplingWeak trials can stop early
New problem, unknown rangesWide random search firstReveals the promising region quickly
Need for a strong baselineRandom search with fixed budgetFair reference for advanced tuners
Choosing when to rely on random search

Fixing the random seed of the sampler and logging every configuration with its score makes the experiment reproducible and auditable. Reporting the distribution of scores across trials, not only the best one, also reveals how sensitive the model is to its hyperparameters.

Limitations and common mistakes

The main weakness of random search is that it does not learn from previous trials. When each evaluation costs hours of GPU time, model-based methods usually reach a good configuration with fewer evaluations. Random search also offers no convergence guarantee to the exact optimum in continuous spaces, only a rising probability of approaching it.

MistakeConsequenceFix
Uniform sampling of learning rateMost trials use very large valuesSample on a log scale
Selecting on the test setOptimistic, biased performance estimateSelect on validation data only
Too few trialsResult depends on luckBudget at least 30 to 60 trials
Single seed per trialNoise mistaken for improvementRepeat top trials with several seeds
Frequent errors and their fixes

A further risk is overfitting the validation set: with hundreds of trials, the best score is partly a product of chance. Nested cross-validation or a final evaluation on an untouched test set gives an honest estimate.

Understanding it simply

Imagine tuning an old radio with several knobs. You could turn each knob in fixed steps and try every combination. That takes a long time. Random search instead sets the knobs to random positions, listens, and repeats. After enough tries, you keep the best sound.

This works well because only one or two knobs usually matter. Random tries test many different positions of those important knobs. A fixed grid tests only a few. The method is simple, and many computers can try settings at the same time.

Applied in practice

A data science team at a regional bank trains a gradient-boosted model to predict loan defaults. The model has six hyperparameters, including learning rate, tree depth and subsampling ratio. A full grid with four values each would need 4,096 training runs, which is far beyond the overnight compute budget.

The team instead runs 100 random trials across 20 cloud workers, sampling the learning rate log-uniformly between 0.005 and 0.3. The whole search finishes in about three hours. The best configuration raises the validation AUC from 0.81 with default settings to 0.84, and a check on a held-out test set confirms 0.835. The team then uses this result as the baseline before trying a Bayesian optimizer.