Split number into 4 random numbers

前端 未结 7 813
-上瘾入骨i
-上瘾入骨i 2020-12-30 08:11

I want to split 10 into an array of 4 random numbers, but neither can be 0 or higher than 4. For example [1,2,3,4],

相关标签:
7条回答
  • 2020-12-30 08:46

    this calculates a random number from 1 to 4

    wrap it on a function to your needs to generate the arrays

    Math.floor(Math.random() * 4) + 1 
    

    var randomNumber = Math.floor(Math.random() * 4) + 1 ;
    console.log(randomNumber);

    0 讨论(0)
提交回复
热议问题