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. To copy the code, double-click inside the frame.

Case 1: Random integer

// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using 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.2.1] Res. 1: [Int] = -421216764
[mXparser-v.5.2.1] Res. 2: [Int] = 859703054

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

// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using org.mariuszgromada.math.mxparser;
// ...

/* -100 <= N <= 100 */
Expression e2 = new Expression("[Int2]");

mXparser.consolePrintln("Res. 1: " + e2.getExpressionString() + " = " + e2.calculate());
mXparser.consolePrintln("Res. 2: " + e2.getExpressionString() + " = " + e2.calculate());

/* -100000 <= N <= 100000 */
Expression e5 = new Expression("[Int5]");

mXparser.consolePrintln("Res. 3: " + e5.getExpressionString() + " = " + e5.calculate());
mXparser.consolePrintln("Res. 4: " + e5.getExpressionString() + " = " + e5.calculate());
[mXparser-v.5.2.1] Res. 1: [Int2] = 92.0
[mXparser-v.5.2.1] Res. 2: [Int2] = 94.0
[mXparser-v.5.2.1] Res. 3: [Int5] = 50442.0
[mXparser-v.5.2.1] Res. 4: [Int5] = -76163.0

Case 3: Random natural number

// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using 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.2.1] Res. 1: [nat] = 1659809708
[mXparser-v.5.2.1] Res. 2: [nat] = 1259835535
[mXparser-v.5.2.1] Res. 3: [Nat] = 248106924
[mXparser-v.5.2.1] Res. 4: [Nat] = 1953526897

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

// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using 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.2.1] Res. 1: [nat1] = 10
[mXparser-v.5.2.1] Res. 2: [nat1] = 0
[mXparser-v.5.2.1] Res. 3: [Nat3] = 90
[mXparser-v.5.2.1] Res. 4: [Nat3] = 51

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

// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using 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.2.1] Res. 1: [Uni] = 0.9203947484394417
[mXparser-v.5.2.1] Res. 2: [Uni] = 0.27088514104678163

Case 6: Normal distribution N(0,1)

// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using 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.2.1] Res. 1: [Nor] = 0.33914374337258346
[mXparser-v.5.2.1] Res. 2: [Nor] = 0.2480653909819784
Nuget – Package Manager

Install-Package MathParser.org-mXparser -Version 6.0.0

Nuget – .NET CLI

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

Nuget – Package Reference

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

Maven – Dependency

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

Maven – Gradle

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

Maven – Gradle (Kotlin)

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

GitHub

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

OTHER DOWNLOAD OPTIONS

Download latest release – v.6.0.0 Picon: .NET bin onlyDownload latest release – v.6.0.0 Picon: JAVA bin onlyDownload latest release – v.6.0.0 Picon: bin + doc

NEWS FROM MATHPARSER.ORG
SOURCE CODE

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

My other creative spaces

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