如何使Math.random()中的数字不低于我所需的数字?
Cards card1 = new Cards();
card1.cardsnumber = Math.random()*21;
int card1int = (int) Math.round(card1.cardsnumber);我怎样才能使card1int从2到21出炉?
发布于 2022-08-31 20:45:51
只需将1添加到所创建的随机数中,然后使用20而不是21
Cards card1 = new Cards();
card1.cardsnumber = (Math.random()*20) + 1;
int card1int = parseInt(Math.round(card1.cardsnumber))https://stackoverflow.com/questions/73561657
复制相似问题