Search code snippets, questions, articles...

Shuffle objects

shuffle(var items) {
    var random = new Random();

    // Go through all elements.
    for (var i = items.length - 1; i > 0; i--) {
      // Pick a pseudorandom number according to the list length
      var n = random.nextInt(i + 1);

      var temp = items[i];
      items[i] = items[n];
      items[n] = temp;
    }

    return items;
  }

Search Index Data (The code snippet can also be found with below search text)

Shuffle
Was this helpful?
0 Comments
Programming Feeds
Learn something new everyday on Devsheet