Javascript generate random unique number every time

后端 未结 7 1319
予麋鹿
予麋鹿 2021-01-15 16:25

Ok so i need to create four randomly generated numbers between 1-10 and they cannot be the same. so my thought is to add each number to an array but how can I check to see i

7条回答
  •  被撕碎了的回忆
    2021-01-15 16:44

    In your answer earlier, you do have a small bug. Instead of

    var originalLength = grabBag.length;
    for(var i = 0; i < originalLength .length; i++){
        console.log(getNextRandom());
    }
    

    I believe you meant:

    var originalLength = grabBag.length;
    for(var i = 0; i < originalLength; i++){
        console.log(getNextRandom());
    }
    

    Thanks.

提交回复
热议问题