-
Notifications
You must be signed in to change notification settings - Fork 0
/
BooleanGenerator.cs
39 lines (30 loc) · 1.05 KB
/
BooleanGenerator.cs
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
36
37
38
39
using System;
using System.Collections.Generic;
using System.Threading;
namespace Peddler {
/// <summary>
/// A generator for creating <see cref="Boolean" /> values.
/// </summary>
public class BooleanGenerator : IDistinctGenerator<Boolean> {
private static ThreadLocal<Random> random { get; } =
new ThreadLocal<Random>(() => new Random());
/// <inheritdoc />
public IEqualityComparer<Boolean> EqualityComparer { get; }
/// <summary>
/// Instantiates a <see cref="BooleanGenerator" /> that will
/// create <see cref="Boolean" /> values with equal liklihood
/// of <c>true</c> and <c>false</c>.
/// </summary>
public BooleanGenerator() {
this.EqualityComparer = EqualityComparer<Boolean>.Default;
}
/// <inheritdoc />
public Boolean Next() {
return random.Value.NextBoolean();
}
/// <inheritdoc />
public Boolean NextDistinct(Boolean other) {
return !other;
}
}
}