monster.util.randomString()

Syntax

monster.util.randomString(length, chars);

Parameters

  • length (mandatory)

Type: Number

Number of character to include in the output string.

  • chars (optional)

Type: String

Default: '23456789abcdefghjkmnpqrstuvwxyz'

Characters to choose from when creating the output string.

Return

This method returns a String.

Description

This method generates a string of length random characters chosen from either the chars parameter or 23456789abcdefghjkmnpqrstuvwxyz by default.

Examples

  • Generate a random string of 5 characters
monster.util.randomString(5);
// output: 'xh3re'
  • Generate a random string of 4 digits only
monster.util.randomString(4, '1234567890');
// output: '6557'

Edit this page here