[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/ArashPartow/exprtk/master/exprtk_simple_example_17.cpp [Back]  [Original]

/*
 **************************************************************
 *         C++ Mathematical Expression Toolkit Library        *
 *                                                            *
 * Simple Example 17                                          *
 * Author: Arash Partow (1999-2025)                           *
 * URL: https://www.partow.net/programming/exprtk/index.html  *
 *                                                            *
 * Copyright notice:                                          *
 * Free use of the Mathematical Expression Toolkit Library is *
 * permitted under the guidelines and in accordance with the  *
 * most current version of the MIT License.                   *
 * https://www.opensource.org/licenses/MIT                    *
 * SPDX-License-Identifier: MIT                               *
 *                                                            *
 **************************************************************
*/


#include 
#include 
#include 
#include 

#include "exprtk.hpp"


template 
struct rnd_01 : public exprtk::ifunction
{
   using exprtk::ifunction::operator();

   rnd_01() : exprtk::ifunction(0)
   { ::srand(static_cast(time(NULL))); }

   inline T operator()()
   {
      // Note: Do not use this in production
      // Result is in the interval [0,1)
      return T(::rand() / T(RAND_MAX + 1.0));
   }
};

template 
void monte_carlo_pi()
{
   typedef exprtk::symbol_table symbol_table_t;
   typedef exprtk::expression   expression_t;
   typedef exprtk::parser       parser_t;

   const std::string monte_carlo_pi_program =
      " var samples[2 * 10^8] := [(rnd_01^2 + rnd_01^2) 

Web Proxy Viewer  |  New URL  |  Original Page