Random(int)

From NWN Lexicon
Jump to: navigation, search

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)

Version

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;

See Also

functions:  GetRandomDelay


author: Tom Cassiotis, editor: Charles Feduke, additional contributor(s): John Harris, Mark Schuit, Harold Myles, Matthew Glisson, Ima Dufas