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.
| Hyperparameter | Typical range | Sampling distribution |
|---|---|---|
| Learning rate | 1e-5 to 1e-1 | Log-uniform |
| Weight decay | 1e-6 to 1e-2 | Log-uniform |
| Dropout rate | 0.0 to 0.5 | Uniform |
| Batch size | 16 to 512 | Discrete powers of two |
| Number of layers | 2 to 12 | Uniform integer |
| Optimizer | SGD, Adam, AdamW | Categorical |
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.
| Method | How candidates are chosen | Main strength | Main weakness |
|---|---|---|---|
| Grid search | Every point of a fixed lattice | Exhaustive and reproducible | Cost grows exponentially with dimensions |
| Random search | Independent random draws | Simple, parallel, robust | Ignores results of earlier trials |
| Bayesian optimization | Surrogate model and acquisition function | Sample-efficient for costly trials | Sequential and harder to scale |
| Hyperband | Random draws with early stopping | Saves compute on weak trials | Needs a meaningful partial budget |
| Tree-structured Parzen estimator | Density models of good and bad trials | Handles conditional spaces well | Needs warm-up trials |
Variants of random search
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.
| Situation | Recommended approach | Reason |
|---|---|---|
| Cheap trials, many workers | Plain random search | Full parallelism outweighs sample efficiency |
| Expensive trials, few workers | Bayesian optimization | Each trial should be chosen carefully |
| Training curves available early | Hyperband with random sampling | Weak trials can stop early |
| New problem, unknown ranges | Wide random search first | Reveals the promising region quickly |
| Need for a strong baseline | Random search with fixed budget | Fair reference for advanced tuners |
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.
| Mistake | Consequence | Fix |
|---|---|---|
| Uniform sampling of learning rate | Most trials use very large values | Sample on a log scale |
| Selecting on the test set | Optimistic, biased performance estimate | Select on validation data only |
| Too few trials | Result depends on luck | Budget at least 30 to 60 trials |
| Single seed per trial | Noise mistaken for improvement | Repeat top trials with several seeds |
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.