Difference between revisions of "GetRandomPercent"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
 
imported>JOG
 
(21 intermediate revisions by 12 users not shown)
Line 2: Line 2:
  GetRandomPercent  
  GetRandomPercent  


Returns a random number from 0-99 inclusive.  
Returns a random, integer number from 0-99 inclusive.  
 
 
To generate a random number between min and max:
<pre>set randVal to min + GetRandomPercent * (max-min+1) / 100</pre>
 
To generate a random number between 1 and max:
<pre>set randVal to 1 + GetRandomPercent * max / 100</pre>
 
 
'''Examples:'''
short dice
set dice to 1 + 0.06 * GetRandompercent  ;  => 1 to 6 (almost equal chances see [[Talk:GetRandomPercent|talk page]])
 
short rnd
set rnd to 5.0/99 * Getrandompercent    ;  => 0 to 5 (only 1% chance for 5! see [[Talk:GetRandomPercent|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==
 
* 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==
 
*[[rand]]


[[Category: Functions]]
[[Category: Functions]]
[[Category:Functions (CS)]]
[[Category: Functions (CS 1.0)]]
[[Category: Condition Functions]]
[[Category: Condition Functions (CS 1.0)]]
[[Category: Miscellaneous Functions]]
[[Category: Miscellaneous Functions]]
[[Category: Condition Functions]]
[[Category: Miscellaneous Functions (CS 1.0)]]
[[Category: Math_Functions]]
[[Category: Math Functions (CS 1.0)]]
 
<!-- Begin Search Terms
Get
Random
Percent
End Search Terms -->

Latest revision as of 15:00, 25 February 2011

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]