or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

array.mdcollection.mddate.mdfunction.mdindex.mdlang.mdmath.mdnumber.mdobject.mdseq.mdstring.mdutil.md
tile.json

number.mddocs/

0

# Number Functions

1

2

Number manipulation utilities for clamping, range checking, and random number generation.

3

4

## Capabilities

5

6

### Number Validation and Constraints

7

8

```javascript { .api }

9

/**

10

* Clamps number within the inclusive lower and upper bounds

11

* @param {number} number - The number to clamp

12

* @param {number} lower - The lower bound

13

* @param {number} upper - The upper bound

14

* @returns {number} Returns the clamped number

15

*/

16

function clamp(number, lower, upper);

17

18

/**

19

* Checks if n is between start and up to, but not including, end

20

* @param {number} number - The number to check

21

* @param {number} start - The start of the range

22

* @param {number} end - The end of the range

23

* @returns {boolean} Returns true if number is in the range, else false

24

*/

25

function inRange(number, start, end);

26

```

27

28

### Random Number Generation

29

30

```javascript { .api }

31

/**

32

* Produces a random number between the inclusive lower and upper bounds

33

* @param {number} lower - The lower bound

34

* @param {number} upper - The upper bound

35

* @param {boolean} floating - Specify returning a floating-point number

36

* @returns {number} Returns the random number

37

*/

38

function random(lower, upper, floating);

39

```

40

41

## Usage Examples

42

43

```javascript

44

import { clamp, inRange, random } from "lodash-es";

45

46

// Clamp values within bounds

47

console.log(clamp(10, 5, 15)); // 10 (within bounds)

48

console.log(clamp(3, 5, 15)); // 5 (clamped to lower)

49

console.log(clamp(20, 5, 15)); // 15 (clamped to upper)

50

51

// Check if number is in range

52

console.log(inRange(3, 2, 4)); // true

53

console.log(inRange(4, 8)); // true (0 to 8)

54

console.log(inRange(4, 2)); // false

55

console.log(inRange(2, 2)); // false

56

console.log(inRange(-3, 2, 4)); // false

57

58

// Generate random numbers

59

console.log(random(0, 5)); // Random integer between 0-5

60

console.log(random(5)); // Random integer between 0-5

61

console.log(random(1.2, 5.2)); // Random float between 1.2-5.2

62

console.log(random()); // Random float between 0-1

63

```