答复: JAVA每日一题01
ruby 代码:
5.times do arr=(1..49).to_a p (0..5).inject([]){|result,index| result << arr.delete_at(rand(49-index))}endresult:
[41, 18, 15, 43, 40, 37][18, 26, 33, 15, 16, 27][14, 44, 49, 42, 8, 20][9, 42, 30, 28, 48, 19][11, 39, 21, 14, 35, 28]
function random(){var result=new Array();function innerRandom(){var result=new Array();var temp=new Array();for(var i=1;i<50;i++){temp.push(i);}for(var i=0;i<5;i++){var index=Math.floor(Math.random() * temp.length);result.push(temp[index]); temp.splice(index, 1);}return result;}for(var i=0;i<5;i++){result.push(innerRandom());}return result;}