Skip to content

Instantly share code, notes, and snippets.

@Hans5958
Last active May 28, 2022 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hans5958/da26f4ca9646868bd68aa1ffc6d61510 to your computer and use it in GitHub Desktop.
Save Hans5958/da26f4ca9646868bd68aa1ffc6d61510 to your computer and use it in GitHub Desktop.

CD Key, JavaScript (Node.js), 234 bytes

(a,b)=>{P=(n,p)=>{for(n=n+"";n.length<p;n="0"+n);return n};R=n=>Math.random()*n|0;F=w=>w.slice(-1);while(!a||(a[0]==a[1]==a[2]>2))a=P(R(999),3);while(!b||(!b.split``.map(n=>t+=n,t=0)%7&&(!F(b)||F(b)>7)))b=P(R(1e7-1),7);return a+"-"+b}

Try it online!

OEM Key, JavaScript (Node.js), 262 bytes

b=>{P=(n,p)=>{for(n=n+"";n.length<p;n="0"+n);return n};R=n=>Math.random()*n|0;F=w=>w.slice(-1);S="99999";a2=R(8)+95+"";if(a2>99)a2=a2.slice(1);while(!b||(!b.split``.map(n=>t+=n,t=0)%7&&(!F(b)||F(b)>7)))b=P(R(S+9),7);return P(R(366),3)+a2+"-OEM-"+b+"-"+P(R(S),5)}

Try it online!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment