Creating randomized GameObject array

Hello. I’m currently trying to create a randomized array of GameObjects from an already established array, the problem being that I don’t want any of the elements to repeat themselves. Essentially, I just want to shuffle the original array contents randomly. I tried to use OrderBy but I got the error:

"UnityEngine.GameObject[ ]’ does not contain a definition for OrderBy' and no extension method OrderBy’ "

This is my code up to this point:

using UnityEngine;
using System.Collections;

public class Comportamiento_principal : MonoBehaviour {


    public GameObject[] listaPreguntas;
    GameObject[] ordenPreguntas;

    void Start () {
    Random rnd = new Random();
    int n=listaPreguntas.Length;
    for (int i=0; i<n; i++){
    ordenPreguntas[i]=listaPreguntas[rnd.Next(0,14)];
  //ordenPreguntas = listaPreguntas.OrderBy(n=> rnd.Next()).ToArray();
    }
    }
   
    void Update () {
   
    }
}

The Enumerable.OrderBy() extension method is a part of the System.Linq namespace, so you’ll need to include that in the script at the top. Here’s the link to the MSDN page, if you’re curious. I would also like to say that I really love this method given on StackOverflow by Matt Howells- it’s not the accepted answer, but it should be.

A simple FIsher-Yates shuffle should do:

// Copy ordenPreguntas from listaPreguntas
for (int i=0;i<listaPreguntas.Length;i++)
          ordenPreguntas[i] = listaPreguntas[i];

// shuffle ordenPreguntas
for (int i=ordenPreguntas.Length-1;i>0;i--)
{
             int j = Random.Range(0,i+1);
            GameObject tmp = ordenPreguntas[j];
             orderPreguntas[j] = orderPreguntas[i];
             orderPreguntas[i] = tmp;
}