using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FisherYates {
	internal class Calculations {
		public static List<T> Shuffle<T>(List<T> list) => Shuffle(list, new Random());

		public static List<T> Shuffle<T>(List<T> list, int seed) => Shuffle(list, new Random(seed));

		static List<T> Shuffle<T>(List<T> list, Random rand) {
			var returned = new List<T>(list);

			for (var i = 2; i < list.Count; i++) {
				var pos = list.Count - i;
				var newPos = pos + rand.Next(1, i - 1);

				var help = returned[pos];
				returned[pos] = returned[newPos];
				returned[newPos] = help;
			}

			return returned;
		}
	}
}
