Lodash Number Methods

Beginner
4 min read
Updated: Nov 2026
3 method guides
Method index

About This Index

This page is the Lodash Number index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs.

Learn math aggregators on /lodash/math. Use this page for bounds and randomness with _.clamp(), _.inRange(), and _.random().

Beginner path.

Start with _.clamp(), then _.inRange() for half-open intervals, and _.random() for bounded picks (not crypto).

How to Call a Number Method

Pass a number and bounds to the Lodash helper:

Lodash
import _ from "lodash";

_.clamp(-10, -5, 5);   // -5
_.clamp(10, -5, 5);    // 5
_.clamp(3, -5, 5);     // 3

_.inRange(3, 2, 4);    // true  (2 <= 3 < 4)
_.inRange(4, 2, 4);    // false (end exclusive)
_.inRange(2, 2);       // false (defaults start=0, end=2)

_.random(0, 5);        // integer 0..5
_.random(1.2, 5.2);    // float in range
_.random(5);           // integer 0..5

Lodash Number Methods Table

All number method guides in this Lodash tutorial series (3 tutorials).

Bounds

2 methods

Clamp values and test half-open numeric ranges.

MethodDescriptionTutorial
_.clamp()Constrain a number between a lower and upper bound.Try it
_.inRange()Return true when the number lies in the half-open interval [start, end).Try it

Generate

1 method

Create bounded random integers or floats.

MethodDescriptionTutorial
_.random()Produce a random integer or floating value between bounds.Try it

Frequently Asked Questions

Three helpers: _.clamp pins a value inside bounds, _.inRange tests membership on a half-open numeric interval, and _.random generates bounded integers or floats.
It uses a half-open interval [start, end), can default start to 0, and swaps bounds when start exceeds end—so you do not accidentally include the exclusive end.
No. It uses Math.random under the hood, which is not cryptographically secure. Use crypto.getRandomValues or crypto.randomBytes for tokens and keys.
Prefer per-method imports: import clamp from 'lodash/clamp' or import { clamp } from 'lodash-es'. You can also use const _ = require('lodash') and call _.clamp().
Start with _.clamp(), then _.inRange() and _.random() from the table below.

Start with _.clamp()

Open the clamp guide—syntax, examples, and FAQs.

_.clamp() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful