You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
a) 生成一个长度为5的空数组arr。
b) 生成一个(2-32)之间的随机整数rand。
c) 把随机数rand插入到数组arr内,如果数组arr内已存在与rand相同的数字,则重新生成随机数rand并插入到arr内[需要使用递归实现,不能使用for/while等循环]
d) 最终输出一个长度为5,且内容不重复的数组arr。
题目描述
a) 生成一个长度为5的空数组arr。
b) 生成一个(2-32)之间的随机整数rand。
c) 把随机数rand插入到数组arr内,如果数组arr内已存在与rand相同的数字,则重新生成随机数rand并插入到arr内[需要使用递归实现,不能使用for/while等循环]
d) 最终输出一个长度为5,且内容不重复的数组arr。
题目解答
补充
JS中生成随机数:
Math.random() ; // 生成[0,1)的随机数,结果不是整数
Math.random()*31; //生成[0,31)的随机数
Math.floor(Math.random()*31); // 生成[0,31)的随机整数
Math.floor(Math.random()*31)+2; //生成[2,33)的随机整数,即[2,32]
The text was updated successfully, but these errors were encountered: