source: branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Common/Extensions.cs @ 11728

Last change on this file since 11728 was 11727, checked in by gkronber, 8 years ago

#2283: worked on grammatical optimization problem solvers (simple MCTS done)

File size: 474 bytes
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6
7namespace HeuristicLab.Common {
8  public static class Extensions {
9    public static bool IsAlmost(this double x, double y) {
10      return Math.Abs(x - y) < 1.0e-6;
11    }
12
13    public static T SelectRandom<T>(this IEnumerable<T> xs, Random rand) {
14      var xsArr = xs.ToArray();
15      return xsArr[rand.Next(xsArr.Length)];
16    }
17  }
18}
Note: See TracBrowser for help on using the repository browser.