Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Extensions/RandomExtensions.cs @ 17603

Last change on this file since 17603 was 15017, checked in by pkimmesw, 7 years ago

#2665 Fixed Benchmark Problem Definition, Converted LoopExpressions to stateless expressions, Added several unit test to ensure funcionality, Fixed UI bugs

File size: 910 bytes
Line 
1using System;
2
3namespace HeuristicLab.Problems.ProgramSynthesis.Push.Extensions {
4  using HeuristicLab.Core;
5
6  public static class RandomExtensions {
7    /// <summary>
8    /// Generates a random biased towards min
9    /// <see href="https://gamedev.stackexchange.com/questions/116832/random-number-in-a-range-biased-toward-the-low-end-of-the-range">Source</see>
10    /// </summary>
11    /// <param name="min">Minimum random int</param>
12    /// <param name="max">Maximum random int</param>
13    /// <param name="biasLevel">The bigger this values is, the bigger is the probability that min will be generated</param>
14    /// <param name="random">Random number generater</param>
15    /// <returns></returns>
16    public static int NextBiased(this IRandom random, int min, int max, double biasLevel) {
17      return (int)(min + (max - min) * Math.Pow(random.NextDouble(), biasLevel));
18    }
19  }
20}
Note: See TracBrowser for help on using the repository browser.