using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace com.deeperbeige.lib
{
    public class Arrays
    {
		// Concatenate two arrays into a new array
		// Original arrays untouched
		public static T[] Concat<T>(T[] a, T[] b)
		{
		    if (a == null) throw new ArgumentNullException("a");
		    if (b == null) throw new ArgumentNullException("b");
			
		    T[] output = new T[a.Length + b.Length];
			
		    Array.Copy(a, 0, output, 0,        a.Length);
		    Array.Copy(b, 0, output, a.Length, b.Length);
			
		    return output;
		}
		
		// In-place unbiased shuffle
		// **** WARNING: UNTESTED ****
	    public static void Shuffle<T> (T[] array)
	    {
	        int n = array.Length;
	        while (n > 1) 
	        {
				int k = Maths.RandomInt(0, --n);
	            T temp = array[n];
	            array[n] = array[k];
	            array[k] = temp;
	        }
	    }
		
		// Select a random element from the given array
		// **** WARNING: UNTESTED ****
	    public static T RandomElement<T> (T[] array)
	    {
			int j = Maths.RandomInt(0, array.Length - 1);
			return array[j];
	    }
	}
}