I have this code that generates me 12 numbers from 1 to 12, then a sorting algorithm sort it out while printing out each step in a matrix.
It's all nice, but I need the random numbers non-repeated from 1 to 12.
Any idea how can I do that?
var a = new Array(12);
var i,j,k,key;
for (j=0; j<12; j++){
a[j]=Math.floor(Math.random()*(13-1)+1);
}
document.write("Numbers:");
document.write("<TABLE align=center border=0><TR>");
for (j=0; j<12; j++){
document.write("<TD align=right width=20>",a[j],
"</TD>");
}
document.write("</TR></TABLE><CENTER><HR></CENTER>")
for (j=1; j<12; j++){
key = a[j]; i=j-1;
while (i>=0 && a[i]>key){
a[i+1] = a[i]; i--
}
a[i+1] = key;
document.write("<TABLE align=center border=0><TR>");
for (k=0; k<12; k++){
if (i<k && k<=j){
document.write("<TD align=right width=20>",
"<FONT COLOR=#ff3333>",a[k],"</FONT></TD>");}
else{
document.write("<TD align=right width=20>",
a[k],"</TD>");}
}
document.write("</TR></TABLE>")
}