<commit_before>/*
 * triangular.cpp
 *
 *  Created on: 18/10/2013
 *      Author: drb
 */

#include "triangular.h"
#include <random>
#include "../area.h"
#include "../Point.h"
#include <iostream>

namespace maths
{
namespace dist
{
  //Reverse triangular distribution, from probability to x value
  double tri_rnd ( double a, double b, double c )
  {
    //Get Random number between 0 and 1
    //double prob = (double)rand()/RAND_MAX;
    double prob = 0.9;
    //Calculate the height of the distribution triangle
    double h = 2 / (b - a);

    //Calculate the position of the probability in the triangle
    double D =  b*c - a*c - a*b + a*a;
    double E =  a*a - D * prob;

    //Find the position of x when the area under is equal to prob
    double x = (2*a + sqrt(4*a*a - 4*E ) ) / 2;

    //Height of point at point x
    double l = (2 * ( x - a )) / ((b-a)*(c-a));

    //Is it higher than the tallest point of the distribution?
    if (l > h) {
        //Yes
        //x = (c-a)/(b-a);
        double P = prob - (c-a)/(b-a);
        double g = (b*b - a*b - b*c + a*c) * (P - (b-c)/(b-a));
        E = (b*b) + g;

        x = (2*b - sqrt(4*(b*b) - 4*E) ) / 2;
    } else {
        //No
        //All done
    }<commit_msg>Turned rand() back on * Removed debug code<commit_after>/*
 * triangular.cpp
 *
 *  Created on: 18/10/2013
 *      Author: drb
 */

#include "triangular.h"
#include <random>
#include "../area.h"
#include "../Point.h"
#include <iostream>

namespace maths
{
namespace dist
{
  //Reverse triangular distribution, from probability to x value
  double tri_rnd ( double a, double b, double c )
  {
    //Get Random number between 0 and 1
    double prob = (double)rand()/RAND_MAX;
    //Calculate the height of the distribution triangle
    double h = 2 / (b - a);

    //Calculate the position of the probability in the triangle
    double D =  b*c - a*c - a*b + a*a;
    double E =  a*a - D * prob;

    //Find the position of x when the area under is equal to prob
    double x = (2*a + sqrt(4*a*a - 4*E ) ) / 2;

    //Height of point at point x
    double l = (2 * ( x - a )) / ((b-a)*(c-a));

    //Is it higher than the tallest point of the distribution?
    if (l > h) {
        //Yes
        //x = (c-a)/(b-a);
        double P = prob - (c-a)/(b-a);
        double g = (b*b - a*b - b*c + a*c) * (P - (b-c)/(b-a));
        E = (b*b) + g;

        x = (2*b - sqrt(4*(b*b) - 4*E) ) / 2;
    } else {
        //No
        //All done
    }
{'fraction_non_alphanumeric': 0.16356275303643725, 'fraction_numerical': 0.01700404858299595, 'mean_word_length': 1.8968347010550997, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4979078', 'n_tokens_mistral': 956, 'n_tokens_neox': 895, 'n_words': 309}