The "rng" app provides a service for random generation.
When writing code that is meant to be invoked by a custom CLI command, you need to insure that the "rng" app is loaded (by defualt, it is only loaded when running the server).
// in an async method, preferable a CLI command handler
await App.initialLoad('rng');
let diceRoll = App.$rng.randomInt(1, 6);
App.$rng.randomFloat(min=0.0, max=1.0)
Returns a random float number between the given min and max.
App.$rng.randomInt(min=1, max=100)
Returns a random number between the given min and max (inclusive).
App.$rng.randomBytes(num)
Returns a random sequence of the given number of bytes.
App.$rng.hexToken(length=32)
Returns a hex token with the given length.
The "rng" app adds the CLI command group "rng" to the CLI, which you can access from your project.
node . rng randint [min=1] [max=100]
Displays a random number between the given minimum and maximum.
$ node . rng randint
80
$ node . rng randint 1 6
3
$ node . rng randint -100 0
-26
node . rng token [len=32]
Displays a random hex token with the given length.
$ node . rng token
8be4a15bd3efa0b04e088de99779eb3e
$ node . rng token 4
82d2