вариант из двух циклов, без повторов и проверок на уникальность, случайность более "равномерная".
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
.active {
background-color: #FF0000;
color: #FFFFFF;
}
</style>
<script>
document.addEventListener( 'DOMContentLoaded' , () => {
const arr = [...document.querySelectorAll('div.status>span.online')]
const limit = 3;
const {length} = arr;
for (let i = 0; i < length; i++) {
const index = Math.floor(Math.random() * length);
[arr[i], arr[index]] = [arr[index], arr[i]];
};
arr.length = limit;
arr.forEach(({classList}) => classList.add('active'));
});
</script>
</head>
<body>
<div class="status"><span class="online">01</span></div>
<div class="status"><span class="online">02</span></div>
<div class="status"><span class="online">03</span></div>
<div class="status"><span class="online">04</span></div>
<div class="status"><span class="online">05</span></div>
<div class="status"><span class="online">06</span></div>
<div class="status"><span class="online">07</span></div>
<div class="status"><span class="online">08</span></div>
<div class="status"><span class="online">09</span></div>
<div class="status"><span class="online">10</span></div>
</body>
</html>