How to generate random array without repetition?
Asked by Sai Siva Kumar about 2 years ago
0
I want to generate a random array without repetition
let array=[2,4,8,16,32]
for(i=0;i<array.length;i++){ let pizza=Math.floor(Math.random()*array.length) console.log(array[pizza]) }
1 Answer
0
const getRandom = () => Math.floor(Math.random()*1000);
const getArray = () => { const array = [] for(let i =0; i<5; i++){ array.push(getRandom()); } return array }
setInterval(()=> console.log(getArray()),2000);
Like and follow and welcome all suggestion for improvement...😄
show more answers
Your answer