Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Revise the upper bound of the random values. #2

Merged
merged 1 commit into from

2 participants

@AOA

The max value of Random.Next is EXCLUSIVE upper bound, so we should set it as the count of the list, rather than count - 1. Otherwise the last item is never selected.

AOA Revise the upper bound of the random values.
The max value of Random.Next is EXCLUSIVE upper bound, so we should
set it as the count of the list, rather than count - 1. Otherwise the last
item is never selected.
2fa7092
@Aaronontheweb Aaronontheweb merged commit 9fad85f into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 29, 2012
  1. Revise the upper bound of the random values.

    AOA authored
    The max value of Random.Next is EXCLUSIVE upper bound, so we should
    set it as the count of the list, rather than count - 1. Otherwise the last
    item is never selected.
This page is out of date. Refresh to see the latest.
Showing with 3 additions and 3 deletions.
  1. +3 −3 Faker/Helpers/ArrayHelpers.cs
View
6 Faker/Helpers/ArrayHelpers.cs
@@ -19,7 +19,7 @@ public static T GetRandomSubSelection<T>(this IEnumerable<T> array, int start, i
var subArray = array.ToList().GetRange(start, count);
//Determine the max length of our incoming array
- var maxLength = subArray.Count - 1;
+ var maxLength = subArray.Count;
return subArray.ElementAt(R.Next(0, maxLength));
}
@@ -27,7 +27,7 @@ public static T GetRandomSubSelection<T>(this IEnumerable<T> array, int start, i
public static IEnumerable<T> GetRandomSelection<T>(this IEnumerable<T> array, int count = 1)
{
//Determine the max length of our incoming array
- var maxLength = array.Count() - 1;
+ var maxLength = array.Count();
//Create a new list to contain our selection...
var randomSelection = new List<T>();
@@ -44,7 +44,7 @@ public static IEnumerable<T> GetRandomSelection<T>(this IEnumerable<T> array, in
public static T GetRandom<T>(this IEnumerable<T> array)
{
//Determine the max length of our incoming array
- var maxLength = array.Count() - 1;
+ var maxLength = array.Count();
return array.ElementAt(R.Next(0, maxLength));
}
Something went wrong with that request. Please try again.