# Random(int)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Returns a pseudo-random number with a range.

int Random(
int nMaxInteger
);

### Parameters

nMaxInteger

Specifies the maximum distance from 0 the return value can be (the maximum distance will always be less than nMaxInteger).

### Description

Returns an integer between 0 and nMaxInteger - 1. The maximum value this can return is 65,534 (one less than the maximum value of a signed integer, 65,535).

### Remarks

This function will work with negative numbers. If nMaxInteger is negative, it will produce a random number between 0 and nMaxInteger + 1. So Random(-3) can return 0, -1, or -2.

### Known Bugs

None (see discussion page)

1.61

### Example

// This will assign the value of 0, 1, 2 or 3 to the variable nValue.
nValue = Random(4);

// This will assign the value of 0, -1, -2, or -3 to the variable nValue.
nValue = Random(-4);

// For non-standard die rolls: This example is for a 30 sided die.
// It will assign a value to the variable nValue with a range of 1
// to 30.
nValue = Random(30) + 1;