[Solved] Norwegian organisasjonsnummer generator [closed]


From the linked site, (code is pretty understandable IMHO):

    var num1 = Math.floor(Math.random()*10);
    var num2 = Math.floor(Math.random()*10);
    var num3 = Math.floor(Math.random()*10);
    var num4 = Math.floor(Math.random()*10);
    var num5 = Math.floor(Math.random()*10);
    var num6 = Math.floor(Math.random()*10);
    var num7 = Math.floor(Math.random()*10);
    var num8 = Math.floor(Math.random()*10);

    // Weights: 3 2 7 6 5 4 3 2
    var weighted = num1*3 + num2*2 + num3*7 + num4*6 + num5*5 + num6*4 + num7*3 + num8*2;
    var remainder = weighted % 11;
    var contr = 11 - remainder;

    if (contr == 11)
        contr = 0;

    //alert("weighted: " + weighted + "\nremainder: " + remainder + "\ncontr: " + contr);

    if (contr == 10)
        return null; // invalid orgnr
    else
        return "" + num1 + num2 + num3 + num4 + num5 + num6 + num7 + num8 + contr; // valid orgnr

solved Norwegian organisasjonsnummer generator [closed]