Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

generate product key in js

function generateUniqeProductKey() {
	let tokens = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
		chars = 5,
		segments = 4,
		keyString = '';
	const getRandomInt = (min, max) =>
		Math.floor(Math.random() * (max - min + 1)) + min;

	for (let i = 0; i < segments; i++) {
		let segment = '';

		for (let j = 0; j < chars; j++) {
			let k = getRandomInt(0, 35);
			segment += tokens[k];
		}

		keyString += segment;

		if (i < segments - 1) {
			keyString += '-';
		}
	}

	return keyString;
}

generateUniqeProductKey() // look like: RESXD-FY1GS-AHBGA-75ZE5
 
PREVIOUS NEXT
Tagged: #generate #product #key #js
ADD COMMENT
Topic
Name
7+1 =