3.6 Random Code
Can be used just about anywhere to add an element of randomness to your script.
syntax
(%random random-clause ...)
random-clause = [percent-chance then-body ...]
Arguments:
percent-chance - integer (0-99)
then-body - anything
Specify a piece of code that has a defined chance of being chosen.
If the total percentages add up to less than 99%, there is a chance that none of them get chosen.
If the total exceeds 99%, only the first 99% will have a chance of occurring.
Random constructs can encompass individual arguments, or even whole blocks of code.
They cannot be nested. To achieve a non-integer chance, use a first random block to define (using %define) which additional random block to run.
BUG: if the first branch is 0, it is still chosen occasionally. Do not include a 0 chance branch as the first branch. Also note that the 100th percent is never chosen.
BUG (AoC/HD/UP): Comments in dead branches are not ignored. Do not include any underlying random syntax (ie. end_random) in such comments. For more information, see this external article: Parser Pitfalls
#lang aoe2-rms <OBJECTS-GENERATION> (create-object 'GOLD (%random [30 (number-of-objects 5)] [50 (number-of-objects 6)] [20 (number-of-objects 7)]))
#lang aoe2-rms <OBJECTS-GENERATION> (%random [10 (create-object 'GOLD (number-of-objects 5))])
procedure
(%random-number min max) → string?
min : any/c max : any/c
Randomize a numeric argument between min and max (inclusive).
Make sure max exceeds min.
Cannot be used within math operations.
#lang aoe2-rms <OBJECTS-GENERATION> (create-object 'GOLD (number-of-objects (%random-number 5 7)) (resource-delta (%random-number -200 300)))