Современное решение JS:
const nums = new Set(); while(nums.size !== 8) { nums.add(Math.ceil(Math.random() * 100)); } console.log([...nums]);