Random(int)

From NWN Lexicon
Revision as of 06:21, 23 December 2017 by 167.60.20.54 (talk) (Undo revision 22540 by 208.91.68.228 (talk))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to 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