Changeset 10407
- Timestamp:
- 01/28/14 11:38:13 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/sources/HeuristicLab.Random/3.3/RandomEnumerable.cs ΒΆ
r9456 r10407 199 199 HashSet<int> chosenIndices = new HashSet<int>(); 200 200 while (chosenIndices.Count < sourceArray.Length) { 201 int index = 0;202 double ball = valueArray[index], sum = random.NextDouble() * total;201 int index = -1; 202 double ball = 0, sum = random.NextDouble() * total; 203 203 while (ball < sum) { 204 204 index++; 205 205 if (!chosenIndices.Contains(index)) 206 ball += valueArray[++index]; 207 } 206 ball += valueArray[index]; 207 } 208 index = index >= 0 ? index : Enumerable.Range(0, sourceArray.Length).First(x => !chosenIndices.Contains(x)); 208 209 yield return sourceArray[index]; 209 210 chosenIndices.Add(index);
Note: See TracChangeset
for help on using the changeset viewer.