So it seems that “Random” (i.e.
nValue = Random(4);) will provide a random number that will necessarily start from 0.
Can’t I choose a random range instead? I’d like my random range to be between 30-90…is that possible? I’d imagine it should be but I couldn’t find it in the nwn lexicon
Add the randomized number to the base, and you’ve got your random range between 30 and 90:
int nValue = 30+Random(61);
Be aware that the first number that can be returned is a zero; so to have a range from (0-60) you need to give Random() a sixty-one as a parameter rather than a sixty. (otherwise, possible results would be 0-59, not 0-60).
smacks self in forehead
That was mathematically easier than I thought.
Much appreciated, sorry for the n00biness.
Be also aware that while being a tremendous resource, the Lexicon is not error-free. For example, the Random() page states:
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).
While in fact Random() can only return values from
[0, 32767) or
(-32767, 0] ranges. Square bracket means inclusion, parenthesis - exclusion.
Check my projects if you require some more sophisticated random functions.
The Lexicon is a wiki, so feel free to correct errors as you find them.
I know, but editing pages requires an account, however the sign-up functions seem to be disabled.
On a side note, just today I also found that
GetSubString(sString, iStart, -1)
returns everything from
sStart to the end of
sString. No need for
GetSubString(sString, iStart, GetStringLength(sString))
or similar. This is also not present on the function’s lexicon page.