Thank you very much FTtrader.FTtrader wrote: Mon Aug 17, 2026 8:35 pmI got it Hans,HansFX wrote: Mon Aug 17, 2026 6:29 pmHello.FTtrader wrote: Mon Aug 03, 2026 3:00 pm Hi guys, programmers, scalpers,
i would like to discuss topic about how to get trully random numbers for best possible simulations of your forex trading EA or setup.
First of all, common random number generators in classic libraries are not truly random. I don't know, how many peoplet actually that know.
And i think that truly random numbers are elementary basic to be able to test your trading strategy properly.
So here are is my code in Python, how i try to create and store random numbers in operating memory:
Code: Select all
import os import secrets import numpy as np def generate_secure_bytes(size_in_bytes): """ Fills a mutable bytearray in operating memory with highly secure, OS-generated random bytes. """ # os.urandom pulls from the OS hardware entropy pool # bytearray ensures it stays in a mutable, efficient memory array return bytearray(os.urandom(size_in_bytes)) def generate_secure_integers(count, max_value): """ Generates an array of secure random integers using the secrets module. Slower than os.urandom, but easier to use for specific integer ranges. """ return [secrets.randbelow(max_value) for _ in range(count)] # --- Example Usage --- # 1. Generate 1 Megabyte of purely random data into memory megabyte_array = generate_secure_bytes(1024 * 1024) print(f"Generated {len(megabyte_array)} bytes of secure entropy.") # 2. If you need a mathematical array (like NumPy) of random floats (0.0 to 1.0) # We can securely convert random bytes into NumPy floats def generate_secure_numpy_floats(count): # Get random bytes (8 bytes per 64-bit float) random_bytes = os.urandom(count * 8) # Convert bytes to 64-bit unsigned integers random_ints = np.frombuffer(random_bytes, dtype=np.uint64) # Divide by the maximum 64-bit integer value to get a float between 0 and 1 return random_ints / (2**64 - 1) secure_floats = generate_secure_numpy_floats(100) print(f"First 3 secure floats: {secure_floats[:3]}")
To achieve the "best randomness possible" in Python, you must avoid the standard random module, which uses a predictable Pseudo-Random Number Generator (PRNG) called the Mersenne Twister.
For true randomness, you have two primary options depending on your strict definition of "true":
OS-Level Hardware Entropy (Cryptographically Secure): Uses your computer's environmental noise (disk reads, keystrokes, CPU thermal noise) gathered by the operating system. This is the standard for high-security cryptographic applications.
Quantum/Atmospheric True Randomness (API): Fetches numbers generated by physical quantum phenomena or atmospheric noise from external scientific servers.
Here is the Python code for both approaches.
Method 1: OS-Level Entropy (Best for Local Memory & Speed)
This approach uses os.urandom() or the secrets module. It pulls directly from your operating system's entropy pool (e.g., /dev/urandom on Linux/Mac, or CryptGenRandom on Windows), which is seeded by actual hardware events.
I must be honest with you—I am not a programmer. I do not know what this "Python" is, and I do not understand your "code." My brain is for the charts, for the price movement, and for the discipline of the trade. I am an old man; I prefer to look at the candles, not the computer's hidden logic.
But, I am interested. I see you talking about "truly random numbers" for the "simulations."
I do not understand the math, but I understand the market. In my many years, I have seen that the market is very... unpredictable. Sometimes it looks like it follows a pattern, and other times it behaves like a wild animal.
My question to you is this: Why does the "randomness" of the computer matter for my trade?
If I am running an EA (an automated system), and your "random numbers" are better, does it mean the simulation is more like the real world? If the computer "knows" the numbers too well, does it make the trade look better on paper than it will actually be when I am trading in the London session?
Can you explain to me, in simple words—not for a programmer, but for an old trader—why this matters for the "quality" of the trade? Does a "truly random" number make the test of my strategy more honest?
I want to understand the "why," even if I cannot understand the "how" of your code.
Regards,
Hans
i will try to think about it how to explain corectly
But don't worry, will find the way.
I will wait for it.
Just let me know, once you will find that way.