forked from giacomelli/GeneticSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomizationExtensions.cs
More file actions
50 lines (46 loc) · 1.96 KB
/
RandomizationExtensions.cs
File metadata and controls
50 lines (46 loc) · 1.96 KB
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
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
namespace GeneticSharp.Domain.Randomizations
{
/// <summary>
/// Extension methods for IRandomization.
/// </summary>
public static class RandomizationExtensions
{
/// <summary>
/// Gets an even integer value between minimum value (inclusive) and maximum value (exclusive).
/// </summary>
/// <returns>The integer.</returns>
/// <param name="randomization">The IRandomization implementation.</param>
/// <param name="min">Minimum value (inclusive).</param>
/// <param name="max">Maximum value (exclusive).</param>
[SuppressMessage("Microsoft.Naming", "CA1720:IdentifiersShouldNotContainTypeNames", MessageId = "int")]
public static int GetEvenInt(this IRandomization randomization, int min, int max)
{
checked
{
var candidate = randomization.GetInt(min, max - 1);
return candidate % 2 == 0 ? candidate : candidate + 1;
}
}
/// <summary>
/// Gets an odd integer value between minimum value (inclusive) and maximum value (exclusive).
/// </summary>
/// <returns>The integer.</returns>
/// <param name="randomization">The IRandomization implementation.</param>
/// <param name="min">Minimum value (inclusive).</param>
/// <param name="max">Maximum value (exclusive).</param>
[SuppressMessage("Microsoft.Naming", "CA1720:IdentifiersShouldNotContainTypeNames", MessageId = "int")]
public static int GetOddInt(this IRandomization randomization, int min, int max)
{
checked
{
var candidate = randomization.GetInt(min, max - 1);
return candidate % 2 != 0 ? candidate : candidate + 1;
}
}
}
}