Thread: Array shuffle

  1. #1
    Registered User
    Join Date
    Dec 2022
    Posts
    1

    Array shuffle

    Write the function shuffle(array) that shuffles (randomly reorders) elements of the array. Multiple runs of shuffle may lead to different orders of elements. For instance: let arr = [1, 2, 3]; shuffle(arr); // arr = [3, 2, 1] shuffle(arr); // arr = [2, 1, 3] shuffle(arr); // arr = [3, 1, 2] //

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    So what have you tried so far?

    I mean, try a simple thing to begin with, like swapping arr[0] and arr[1]
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A General Shuffle Array Function
    By G4143 in forum C Programming
    Replies: 8
    Last Post: 01-02-2023, 06:10 AM
  2. Shuffle rows in an array
    By Justin Time in forum C Programming
    Replies: 2
    Last Post: 04-23-2015, 07:39 PM
  3. String Array Shuffle
    By omGeeK in forum C Programming
    Replies: 3
    Last Post: 02-14-2011, 07:48 PM
  4. shuffle 2-dimensional array
    By patkhor in forum C Programming
    Replies: 5
    Last Post: 11-26-2008, 03:51 PM
  5. Array Shuffle
    By ypramesh in forum C Programming
    Replies: 2
    Last Post: 04-08-2006, 11:01 AM