Question: I am using last version of ActiveMQ Artemis.

My use case is pretty simple. The broker sends a lot of messages to consumer - a single queue. I have 2 consumers per queue. Consumers are set to use default prefetch size of messages (1000).

Is there a way to monitor how many messages are pre-fetch and processed from each consumer?

Answer: 
There are several ways you can go about "shuffling" an array. I chose the Fisher-Yates method in an experimental "war" card game.
<https://github.com/scottm85/war/blob/master/src/Game/Deck.js#L80>

```
shuffle()
{
    /* Use a Fisher-Yates shuffle...If provides a much more reliable shuffle than using variations of a sort method https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle */
    let cards = this.cards;
    for (let i = cards.length - 1; i > 0; i--)
    {
        let j = Math.floor(Math.random() * (i + 1)); // random index from 0 to i
        [cards[i], cards[j]] = [cards[j], cards[i]];
    }
    this.cards = cards;

    console.log("----------------- Deck Shuffled -----------------");
}

```

<https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle>

Granted my provided example is slightly different than your needs as I was doing this in react, had a Deck array built out, and wasn't using JS for direct DOM manipulation. In theory though, you could modify this to work with your method. Something like this:

```
function shuffleCards
{
    let cards = document.querySelectorAll('.card');
    let cardsArray = Array.from(cards);

    for (let i = cardsArray.length - 1; i > 0; i--)
    {
        let j = Math.floor(Math.random() * (i + 1)); // random index from 0 to i
        [cardsArray[i], cardsArray[j]] = [cardsArray[j], cardsArray[i]];
        cards[i].remove();
    }

    cardsArray.forEach(t => document.body.appendChild(t));
}

```
Others have provided algorithms for the randomization portion, but here is how you can handle the detaching and reattaching portion. [`removeChild()`](https://developer.mozilla.org/en-US/docs/Web/API/Node/removeChild) will get you the node detached from the DOM and [`appendChild()`](https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild) will allow you to add it. Just be careful with attaching and detaching. Events can get a bit messy especially if you end up cloning the node somewhere down the line rather than just attaching it again.

```js
(function shuffleCards() {
  let container = document.querySelector('#container');
  let cards = container.querySelectorAll('.card');

  [...cards].map(
    node => container.removeChild(node)
  ).sort(
    () => Math.random() - 0.5 // shamelessly stolen from Alireza Ahmadi
  ).forEach(
    node => container.appendChild(node)
  );
})()
```

```html
<div id="container">
  <div class="card" data-card="1" onclick="cardClicked(this)">
      Card 1
  </div>
  <div class="card" data-card="7" onclick="cardClicked(this)">
      Card 2
  </div>
  <div class="card" data-card="1" onclick="cardClicked(this)">
      Card 3
  </div>
  <div class="card" data-card="1" onclick="cardClicked(this)">
      Card 4
  </div>
  <div class="card" data-card="1" onclick="cardClicked(this)">
      Card 5
  </div>
  <div class="card" data-card="1" onclick="cardClicked(this)">
      Card 6
  </div>
  <div class="card" data-card="1" onclick="cardClicked(this)">
      Card 7
  </div>
  <div class="card" data-card="1" onclick="cardClicked(this)">
      Card 8
  </div>
  <div class="card" data-card="1" onclick="cardClicked(this)">
      Card 9
  </div>
  <div class="card" data-card="1" onclick="cardClicked(this)">
      Card 10
  </div>
</div>
```