生成6个54以内的随机数,还能改进吗
生成6个54以内的随机数import java.util.Random;
class DifferentRandomNum
{
public static void main(String[] args)
{
int[] records = new int[55];
int[] num = new int[6];
int tmp=0;
for(int i = 0;i<6;i++)
{
for(;;)
{
tmp = (int)(Math.random()*55);
if(records[tmp]==0)
{
num[i]=tmp;
records[tmp]++;
}
if(num[i]!=0)break;
}
}
for(int j = 0;j<6;j++)
System.out.println (num[j]);
}
}