Skip to content

Instantly share code, notes, and snippets.

@rheajt
Created December 8, 2016 17:44
Show Gist options
  • Select an option

  • Save rheajt/6c14924f142d3c88af708eec793b76df to your computer and use it in GitHub Desktop.

Select an option

Save rheajt/6c14924f142d3c88af708eec793b76df to your computer and use it in GitHub Desktop.
CODEGENERATOR
function CODEGENERATOR() {
var allCodes = []; // get all of the codes from all of the teacher sheets
var letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'];
var codeLen = 7;
var code = '';
for(var i = 0; i < codeLen; i++) {
var randNum = Math.floor(Math.random() * 9);
var randLetter = Math.floor(Math.random() * letters.length);
var lon = Math.round(Math.random());
if(lon === 0) {
code += letters[randLetter].toUpperCase();
} else {
code += randNum;
}
}
// if(allCodes.indexOf(code) === -1) {
// // it is a unique code
// }
return code;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment