Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/Extensions.cs @ 11659

Last change on this file since 11659 was 11659, checked in by gkronber, 9 years ago

#2283 initial import of implementation of grammatical optimization problem instances

File size: 500 bytes
RevLine 
[11659]1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6
7namespace HeuristicLab.Problems.GrammaticalOptimization {
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.