select random value NOT in array

后端 未结 3 826
情歌与酒
情歌与酒 2021-01-20 07:39

How would I select a random value (0 to 30) that is not in this array?

var list = new Array(1,3,4,7,8,9);
3条回答
  •  伪装坚强ぢ
    2021-01-20 08:14

    function RandomValueNotInArray(array)
    {
        var e;
        do
        {
            e = Math.random() * 31; // n + 1
        } while (array.contains(e))
        return e;
    }
    

提交回复
热议问题