random_generator fields and methods A field is a plain fact about the value, read with a dot and no brackets: $value.name. A method takes arguments or does work, and is called with ->: $value->name(arguments), or with the value piped in: $value |> name(arguments).
From KScript.Math These need <import package="KScript.Math" />import KScript.Math . See KScript.Math .
A fraction from 0 up to (not including) 1. $rng->float() < 0.3 is true three times in ten.
Example
.kscript XML Copy
<import package="KScript.Math" />
<let name="rng" value="@random_generator('000102030405060708090a0b0c0d0e0f')" />
<echo>{ $rng->float() }</echo>.kscript XML Copy
import KScript.Math
$rng = @random_generator('000102030405060708090a0b0c0d0e0f')
echo $rng->float()# random_generator ->int (low: number , high: number ) → number KScript.Math A whole number from low to high, both included.
Arguments can be named: ->int(…, high: …).
Example
.kscript XML Copy
<import package="KScript.Math" />
<let name="rng" value="@random_generator('000102030405060708090a0b0c0d0e0f')" />
<echo>{ $rng->int(1, 6) }</echo>.kscript XML Copy
import KScript.Math
$rng = @random_generator('000102030405060708090a0b0c0d0e0f')
echo $rng->int(1, 6)The next number: a whole number from 0 to 4294967295.
Example
.kscript XML Copy
<import package="KScript.Math" />
<let name="rng" value="@random_generator('000102030405060708090a0b0c0d0e0f')" />
<echo>{ $rng->next() }</echo>.kscript XML Copy
import KScript.Math
$rng = @random_generator('000102030405060708090a0b0c0d0e0f')
echo $rng->next()# random_generator ->pick (list: list ) → any KScript.Math One item of the list.
Parameter Takes list required list
Example
.kscript XML Copy
<import package="KScript.Math" />
<let name="rng" value="@random_generator('000102030405060708090a0b0c0d0e0f')" />
<echo>{ $rng->pick(['red', 'green', 'blue']) }</echo>.kscript XML Copy
import KScript.Math
$rng = @random_generator('000102030405060708090a0b0c0d0e0f')
echo $rng->pick(['red', 'green', 'blue'])# random_generator ->shuffle (list: list ) → list KScript.Math A copy of the list in a random order (Fisher-Yates, from the end).
Parameter Takes list required list
Example
.kscript XML Copy
<import package="KScript.Math" />
<let name="rng" value="@random_generator('000102030405060708090a0b0c0d0e0f')" />
<echo>{ $rng->shuffle([1, 2, 3, 4]) }</echo>.kscript XML Copy
import KScript.Math
$rng = @random_generator('000102030405060708090a0b0c0d0e0f')
echo $rng->shuffle([1, 2, 3, 4])Methods from any