-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathRandomise.cs
More file actions
35 lines (32 loc) · 956 Bytes
/
Randomise.cs
File metadata and controls
35 lines (32 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AdvancedOCR
{
static class Randomisation
{
public static IList<T> Randomise<T>(this IList<T> items)
{
Random random = new Random();
return items.Randomise(random);
}
public static IList<T> Randomise<T>(this IList<T> items, int seed)
{
return items.Randomise(new Random(seed));
}
public static IList<T> Randomise<T>(this IList<T> items, Random random)
{
List<T> result = new List<T>(items);
for (int i = 0; i < result.Count; i++)
{
T item = result[i];
int newPosition = random.Next(result.Count);
result[i] = result[newPosition];
result[newPosition] = item;
}
return result;
}
}
}