CAROLINA DOCS


RNG

The "rng" app provides a service for random generation.

The RNG Service

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);

Generating a Random Float

App.$rng.randomFloat(min=0.0, max=1.0)

Returns a random float number between the given min and max.

Generating a Random Integer

App.$rng.randomInt(min=1, max=100)

Returns a random number between the given min and max (inclusive).

Generating Random Bytes

App.$rng.randomBytes(num)

Returns a random sequence of the given number of bytes.

Generating a Random Hex Token

App.$rng.hexToken(length=32)

Returns a hex token with the given length.

CLI Commands

The "rng" app adds the CLI command group "rng" to the CLI, which you can access from your project.

Displaying a Random Integer

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

Display a Random Token

node . rng token [len=32]

Displays a random hex token with the given length.

$ node . rng token
8be4a15bd3efa0b04e088de99779eb3e
$ node . rng token 4
82d2

CAROLINA DOCS