React Native
React Native
Generating Random ASCII Strings
See more PRNG Examples
Demonstrates how to generate random us-ascii strings.Chilkat React Native Downloads
import { Prng } from '@chilkat/react-native'
function chilkatExample() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const fortuna = new Prng();
let bDigits = false;
let bLowercase = false;
let bUppercase = false;
// Generate random strings having only lowercase chars (a-z)
// Disallow digits and uppercase and only allow lowercase
bDigits = false;
bUppercase = false;
bLowercase = true;
console.log('-- only lowercase alpha (a-z)');
for (let i = 1; i <= 10; i++) {
// Generate 20-character strings.
console.log(fortuna.randomString(20, bDigits, bLowercase, bUppercase));
}
// Allow both lowercase and uppercase alpha chars
bUppercase = true;
console.log('-- lower and uppercase alpha (a-zA-Z)');
for (let i = 1; i <= 10; i++) {
// Generate 20-character strings.
console.log(fortuna.randomString(20, bDigits, bLowercase, bUppercase));
}
// Allow digits (0-9)
bDigits = true;
console.log('-- digits and lower/uppercase alpha (0-9a-zA-Z)');
for (let i = 1; i <= 10; i++) {
// Generate 20-character strings.
console.log(fortuna.randomString(20, bDigits, bLowercase, bUppercase));
}
// Allow only digits (0-9)
bUppercase = false;
bLowercase = false;
console.log('-- only digits (0-9)');
for (let i = 1; i <= 10; i++) {
// Generate 20-character strings.
console.log(fortuna.randomString(20, bDigits, bLowercase, bUppercase));
}
}