xoshiro256 Random Number Generator
Info
The xoshiro256 Random Number Generator is a Library for MetaTrader 5 that xoshiro256** random number generator xoshiro256** (named after its operations: xor, shift, rotate) is a pseudorandom number generator designed by sebastiano vigna in collaboration with david blackmanthis is a 64-bit all-purpose, rock-solid generator. It has excellent (sub-ns) speed, a state size (256 bits) that is large enough for any parallel application, and it passes all known statistical tests.
Usage
This tool is typically used for enhancing chart analysis and decision making.
Platform
This Library works exclusively on MetaTrader 5 (both build 600+ and newer versions).
Setup
Place the downloaded file in MQL5/Libraries folder via File ? Open Data Folder in MetaTrader 5.
How to Install and Use xoshiro256 Random Number Generator
1. Storage: Place library files in the MQL/Libraries directory to ensure they are accessible to your projects.
2. Implementation: Include the library in your code using the #import directive, ensuring you match the exact function names and parameters.
3. Compilation: Ensure the library is present in the directory before you compile your main EA or script, as the compiler links them during this phase.
4. Management: Keep libraries organized in sub-folders if you manage many custom functions to maintain a clean project structure.
Frequently Asked Questions
Q: What is a library file used for? A: Libraries store reusable code modules, allowing you to centralize common logic used by multiple EAs or indicators.
Q: Is a library executable? A: No, libraries are non-executable files containing functions; they must be imported into an EA, indicator, or script to function.
Q: Can I update a library while the platform is running? A: You should compile your EA or script after updating a library to ensure the latest code changes are integrated.
What this tool does
Xoshiro256** Random Number Generator xoshiro256** (named after its operations: XOR, shift, rotate) is a pseudorandom number generator designed by Sebastiano Vigna in collaboration with David BlackmanThis is a 64-bit all-purpose, rock-solid generator.
Typical Use Case
This Library excels in automated trading and technical analysis on MetaTrader 5.
Compatible Platform & Setup
This Library works on MetaTrader 5. Place the file in the MQL5/Libraries folder and restart the terminal.
Description & Settings
Related: Class CRandom - another powerful library for MetaTrader 5 traders.
Xoshiro256** Random Number Generatorxoshiro256** (named after its operations: XOR, shift, rotate) is a pseudorandom number generator designed by Sebastiano Vigna in collaboration with David Blackman
Also recommended: Comment - similar library with strong performance on MetaTrader 5.
This is a 64-bit all-purpose, rock-solid generator. It has excellent (sub-ns) speed, a state size (256 bits) that is large enough for any parallel application, and it passes all known statistical tests.The xoshiro256** algorithm is not suitable for cryptographic purposes, but is very fast and has excellent statistical properties.
It is presently used in Microsoft's .NET framework and the JavaScript engines of Chrome, Node.js, Firefox, Safari and Microsoft Edge.
The algorithm used here is translated from the reference source code by David Blackman and Sebastiano Vigna.
For MetaTrader programmers and traders, this is highly relevant for:
Monte Carlo Simulations
: Accurately simulating price movements, option pricing, or other stochastic processes.
Backtesting and Strategy Optimization
: Generating random data or events to test the robustness of a trading strategy under various market conditions.
Indicator and Expert Advisor (EA) Development
: Providing a reliable source of randomness for EAs that use randomized logic, such as in genetic algorithms for optimization.
Research and Analysis
: The RandomDoubleHighRes method is particularly useful for researchers and quantitative analysts who require a higher degree of precision for their simulations and models, ensuring more accurate and reliable results than standard ().
Class Xoshiro256
The class provides an easy interface for random number generation.
If your are doing a lot of Monte Carlo simulations, then this xoshiro256** generator will be much faster and more accurate than MQL's MathRand():
Updates:
2023.01.06 - v.1.01 :
Updated the class to use the more robust 64-bits xoshiro256** random number generator, instead of the 32-bits xoshiro128**.
2025.08.01 - v.1.02 :
Added a seedable constructor with a single ulong. The four 64-bit state variables would be generated using SplitMix64 function.
Increased performance of all the public methods for generating random numbers.
2025.08.03 - v.1.03 :
Added RandomDoubleHighRes, a new method for generating high-resolution random doubles in the range of [0.0, 1.0). This method is designed to be more precise than RandomDouble, as it can generate all possible double-precision floating-point values within the specified interval, a feature important for scientific simulations and other high-precision applications.
Corrected potential infinite loop bugs in RandomDouble and RandomDoubleHighRes methods.
Corrected the implementation of RandomBoolean. 2025.08.03 - v.1.04 :
Faster generation of unbiased random integers in a range by using method. This technique replaces the slow modulo reduction with a debiased integer multiplication.
2025.08.28 - v.1.05
Improved RNG seeding mechanism to enforce strong bit-avalanche.
Ensures even closely related seeds (e.g., 0 vs. 1) generate different sequences.
Prevents correlations between runs and overlap across concurrent RNG instances
2025.09.13 - v.1.06
Allow richer initialization by using full entropy from all four 64-bit seeds independently. 2025.09.16 - v.1.07
Implemented SHA-256 based seeding (uses with CRYPT_HASH_SHA256) to preserve full 256-bit entropy,
2025.09.19 - v.1.08
Added sampling utilities (Shuffle, Sample, SampleWithReplacement) to the Xoshiro256 class.
2025.10.02 - v.1.09
Implemented a dedicated boundedUInt32 function using the 32-bit variant of Lemire's fastrange to improve performance.
A BITMAP generated from xoshiro256** Random Number Generator
The code is also mirrored on Algo Forge here:
You may also like: Inc Tema On Array - excellent alternative for library users on MetaTrader 5.
⚠ Limitations & Risk Warning
- This tool is provided for educational and testing purposes only.
- Past performance does not guarantee future results.
- Trading involves substantial risk of loss. Use on a demo account first.
- Results may vary depending on market conditions, broker, and settings.
- We recommend thorough backtesting and forward testing before using with real funds.