ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

Randomize

Randomizes am IEnumerable<T>

Source

public static class Extensions
{
	public static IEnumerable<T> Randomize<T>(this IEnumerable<T> source)
	{
		return source.OrderBy (s => Guid.NewGuid() );
	}
}

Example

void Main()
{
	var ints = new[] {1,2,3,4,5,6,7,8,2,3,4,12,243,4,5,34,24,3,45,45,6,45,6,34,56,534};
	ints.Randomize().Dump();
}

Author: Joe

Submitted on: 3 jul. 2010

Language: C#

Type: System.Collections.Generic.IEnumerable<T>

Views: 4614