Built-in Random Variables

TO SUPPORT MY WORK, ORDER A COMMERCIAL LICENSE
THANK YOU!

The tutorial consists of more than 200 live examples from 50 sections. Each of the examples can be copied and run on your own environment. In addition, mXparser provides an extensive collection of over 500 built-in math functions, expressions and symbols. Familiarize yourself with the scope and the syntax. Live testing is the best way to learn. Good luck! 🙂

Tutorial Math Collection API spec Download

Below is the code for JAVA, the code for C# is almost identical.

Case 1: Random integer

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("[Int]");
mXparser.consolePrintln("Res. 1: " + e.getExpressionString() + " = " + (int)e.calculate());
mXparser.consolePrintln("Res. 2: " + e.getExpressionString() + " = " + (int)e.calculate());
[mXparser-v.5.0.0] Res. 1: [Int] = 442074650
[mXparser-v.5.0.0] Res. 2: [Int] = 1214159232

Case 2: Random integer N: -10^k <= N <= 10^k for k = 1, 2, …,9

/* -100 <= N <= 100 */
Expression e2 = new Expression("&#91;Int2&#93;");
mXparser.consolePrintln("Res. 1: " + e2.getExpressionString() + " = " + e2.calculate());
mXparser.consolePrintln("Res. 2: " + e2.getExpressionString() + " = " + e2.calculate());
/* -100000 <= N <= 100000 */
Expression e5 = new Expression("&#91;Int5&#93;");
mXparser.consolePrintln("Res. 3: " + e5.getExpressionString() + " = " + e5.calculate());
mXparser.consolePrintln("Res. 4: " + e5.getExpressionString() + " = " + e5.calculate());
&#91;/java&#93;
<!-- /wp:shortcode -->

<!-- wp:shortcode -->

[mXparser-v.5.0.0] Res. 1: [Int2] = -48.0
[mXparser-v.5.0.0] Res. 2: [Int2] = -3.0
[mXparser-v.5.0.0] Res. 3: [Int5] = 98.0
[mXparser-v.5.0.0] Res. 4: [Int5] = -9073.0

Case 3: Random natural number

import org.mariuszgromada.math.mxparser.*;
...
/* Including 0 */
Expression e1 = new Expression("[nat]");
mXparser.consolePrintln("Res. 1: " + e1.getExpressionString() + " = " + (int)e1.calculate());
mXparser.consolePrintln("Res. 2: " + e1.getExpressionString() + " = " + (int)e1.calculate());
/* Excluding 0 */
Expression e2 = new Expression("[Nat]");
mXparser.consolePrintln("Res. 3: " + e2.getExpressionString() + " = " + (int)e2.calculate());
mXparser.consolePrintln("Res. 4: " + e2.getExpressionString() + " = " + (int)e2.calculate());
[mXparser-v.5.0.0] Res. 1: [nat] = 575008372
[mXparser-v.5.0.0] Res. 2: [nat] = 1075878155
[mXparser-v.5.0.0] Res. 3: [Nat] = 1456379413
[mXparser-v.5.0.0] Res. 4: [Nat] = 317300480

Case 4: Random natural number N <= 10^k for k = 1, 2, …,9

import org.mariuszgromada.math.mxparser.*;
...
/* Including 0: 0 <= N < 10 */
Expression e1 = new Expression("[nat1]");
mXparser.consolePrintln("Res. 1: " + e1.getExpressionString() + " = " + (int)e1.calculate());
mXparser.consolePrintln("Res. 2: " + e1.getExpressionString() + " = " + (int)e1.calculate());
/* Excluding 0: 0 < N < 1000 */
Expression e2 = new Expression("[Nat3]");
mXparser.consolePrintln("Res. 3: " + e2.getExpressionString() + " = " + (int)e2.calculate());
mXparser.consolePrintln("Res. 4: " + e2.getExpressionString() + " = " + (int)e2.calculate());
[mXparser-v.5.0.0] Res. 1: [nat1] = 0
[mXparser-v.5.0.0] Res. 2: [nat1] = 7
[mXparser-v.5.0.0] Res. 3: [Nat3] = 726
[mXparser-v.5.0.0] Res. 4: [Nat3] = 265

Case 5: Uniform continuous distribution U(0,1)

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("[Uni]");
mXparser.consolePrintln("Res. 1: " + e.getExpressionString() + " = " + e.calculate());
mXparser.consolePrintln("Res. 2: " + e.getExpressionString() + " = " + e.calculate());
[mXparser-v.5.0.0] Res. 1: [Uni] = 0.2880787240212339
[mXparser-v.5.0.0] Res. 2: [Uni] = 0.13848791690555995

Case 6: Normal distribution N(0,1)

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("[Nor]");
mXparser.consolePrintln("Res. 1: " + e.getExpressionString() + " = " + e.calculate());
mXparser.consolePrintln("Res. 2: " + e.getExpressionString() + " = " + e.calculate());
[mXparser-v.5.0.0] Res. 1: [Nor] = -2.43166680373401
[mXparser-v.5.0.0] Res. 2: [Nor] = 0.6602054150950812
Nuget – Package Manager

Install-Package MathParser.org-mXparser -Version 5.2.0

Nuget – .NET CLI

dotnet add package MathParser.org-mXparser --version 5.2.0

Nuget – Package Reference

<PackageReference Include="MathParser.org-mXparser" Version="5.2.0"/>

Maven – Dependency

<dependency>
<groupid>
org.mariuszgromada.math</groupid>
<artifactid>
MathParser.org-mXparser</artifactid>
<version>
5.2.0</version>
</dependency>

Maven – Gradle

implementation 'org.mariuszgromada.math:MathParser.org-mXparser:5.2.0'

Maven – Gradle (Kotlin)

implementation("org.mariuszgromada.math:MathParser.org-mXparser:5.2.0")

GitHub

git clone https://github.com/mariuszgromada/MathParser.org-mXparser

OTHER DOWNLOAD OPTIONS

Download latest release – v.5.2.0 Orion: .NET bin onlyDownload latest release – v.5.2.0 Orion: JAVA bin onlyDownload latest release – v.5.2.0 Orion: bin + doc

NEWS FROM MATHPARSER.ORG
SOURCE CODE

Source code .zipSource code .tar.gz
View on GitHubMathSpace.pl

DONATION
Did you find the software useful?
Please consider donation 🙂
DONATE