Range of Numbers in Arrays & fisher yates shuffle
1. not allow same random numbers to be in the array more than 1 time.
to achieve that probably the only way without to many checks is to use a predefined array containing all your numbers.
function numberArray(a,b){// highest number, just a placeholder
b=[];while(a--)b[a]=a+1;return b
}
this creates an array of numbers , where a is the highest number...
So if you want to have 90 numbers... var myNumbers=numberArray(90);
Shuffle this array. this code is based on the famous fisher yates shuffle.
function shuffleArray(d,c,b,a){//the array to shuffle, just placeholders...
for(c=d.length-1;c>0;c--){
b=Math.floor(Math.random()*(c+1));
a=d[c];d[c]=d[b];d[b]=a
}
};
to shuffle myNumbers
and extract the first 6 numbers:
shuffleArray(myNumbers);
var winningNumbers=myNumbers.slice(0,6);
Demo
http://jsfiddle.net/L17968n4/
2. the first line of numbers mark them in the table with yellow and the second line of numbers mark them with blue.
if you explain that better pls, anyway using css class!
3. if the first numbers and the second numbers are the same (random numbers) mark them in the table with green.
you need to loop trough the array and check if numbers present in the first array are equal to numbers in the second array.
something like that...
numbersLottery.lastIndexOF(myNumbers[0])!==-1;
this checks if the first number of myNumbers is present in the winning numbers array.
DEMO2
maybe this is what you want if i understand correctly...
http://jsfiddle.net/L17968n4/2/
DEMO3
based on comments image
http://jsfiddle.net/L17968n4/5/
and counting the correct numbers
http://jsfiddle.net/L17968n4/7/
shorter&faster shuffle function..
function shuffledArray(a,b,c,d){//array,placeholder,placeholder,placeholder
c=a.length;
while(c)b=Math.random()*(--c+1)|0,d=a[c],a[c]=a[b],a[b]=d;
}
PERFORMANCE vs other shuffle functions: http://jsperf.com/fyshuffle
if you have any questions about the code just ask....