String.getRandom

Syntax

PP.String.getRandom(length: Number);

Parameters

length. Length of the string to format.

Description

The getRandomString static method returns a string of specified length composed of random Latin charaters.

Comments

This method returns a String-type value.

NOTE. This method replaces the outdated PP.getRandomString method.

Example

To execute the example, add a link to PP.js scenario file to HTML page. Create a string consisting of three random Latin characters and repeat it three times using a hyphen as a separator:

// Set a string consisting of three Latin characters
var result = PP.String.getRandom(3);
console.log("Random tring: «" + result + "»");
// Repeat the string three times separated with space
result = PP.String.repeat(result, 3, "-");
console.log("Obtained string: «" + result + "»");

After executing the example the browser console displays a randomly generated string consisting of three Latin characters, and also the same string repeated three times with a hyphen as a separator:

Random string: bfc

Resulting string: «bfc-bfc-bfc»

See also:

PP