PP.String.getRandom(length: Number);
length. Length of the string to format.
The getRandomString static method returns a string of specified length composed of random Latin charaters.
This method returns a String-type value.
NOTE. This method replaces the outdated PP.getRandomString method.
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: