GetRandomPercent

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search

Syntax:

GetRandomPercent 

Returns a random, integer number from 0-99 inclusive.


To generate a random number between min and max:

set randVal to min + GetRandomPercent * (max-min+1) / 100

To generate a random number between 1 and max:

set randVal to 1 + GetRandomPercent * max / 100


Examples:

short dice
set dice to 1 + 0.06 * GetRandompercent  ;  => 1 to 6 (almost equal chances see talk page)
short rnd
set rnd to 5.0/99 * Getrandompercent     ;  => 0 to 5 (only 1% chance for 5! see talk page)
float rnd
set rnd to 0.05 * Getrandompercent       ;  => 0.00 to 4.95 
float rnd
set rnd to 5.0/99 * Getrandompercent       ;  => 0.00 to 5.00 

Notes[edit | edit source]

  • GetRandomPercent does not always operate as expected during the OnLoad phase. It appears to only execute once, so if you have multiple scripts using it, they will all get the same result rather than each getting a different result. This is not a problem during other phases.

See Also[edit | edit source]