我如何防止从随机数重复数字.我需要在1到9之间生成5个不同的数字.我经常会得到像23334这样的数字,我该如何防止?任何帮助都会很棒!
int num2 = (int) Math.round((Math.random()*9) +1);
int num1 = (int) Math.round((Math.random()*9) +1);
int num5 = (int) Math.round((Math.random()*9) +1);
int num3 = (int) Math.round((Math.random()*9) +1);
int num4 = (int) Math.round((Math.random()*9) +1);
Run Code Online (Sandbox Code Playgroud)