Solved Problem with Math.random()
-
That's true.
i agree with you.but for some reasons .. i can't move on the C++ side for now.
but as u said, it is a JS command, so ... is there a missing dependency or OS package that needs to be installed 1st to let JS works well in QT ?
maybe there is some QT versions that has a problems with JS ? if so .. which recommended version of QT shall i install alongside QT Creator version ?
-
@MostafaGamal said in Problem with Math.random():
need a logical reason for not being work correctly for just upgrading my OS !
There are many possibilities.
Do you have an AMD Ryzen CPU? Some models and BIOS versions have faulty random number generators (RNGs): https://forum.manjaro.org/t/i-get-a-cpu-random-generator-warning-advising-me-to-disable-hardware-random-number-generation/116796
- Try updating your BIOS
- Run some tests using rng-tools: https://wiki.archlinux.org/index.php/Rng-tools (the article is for Arch Linux but the same tools exist in Ubuntu repos)
-
@MostafaGamal said in Problem with Math.random():
but for some reasons .. i can't move on the C++ side for now.
you should really consider it, because you're reinventing the wheel ;)
Qt has a nice and easy to use QUuid class
simply wrap it in a basic class and expose it to QML and import it where you need it. -
@JKSH
Yes, i have the same processor as in the forum post : AMD Ryzen 7 3700X 8-Core @ 16x 3.6GHz
if updating BIOS is the solution ... which BIOS version shall i install ? (My MotherBoard is : Gigabyte B450 Aorus Pro Wifi)also installed rng-tools for testing.
that was the output of commandrngtest -c 1000 </dev/random
rngtest 5
Copyright (c) 2004 by Henrique de Moraes Holschuh
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.rngtest: starting FIPS tests...
rngtest: bits received from input: 20000032
rngtest: FIPS 140-2 successes: 999
rngtest: FIPS 140-2 failures: 1
rngtest: FIPS 140-2(2001-10-10) Monobit: 0
rngtest: FIPS 140-2(2001-10-10) Poker: 0
rngtest: FIPS 140-2(2001-10-10) Runs: 1
rngtest: FIPS 140-2(2001-10-10) Long run: 0
rngtest: FIPS 140-2(2001-10-10) Continuous run: 0
rngtest: input channel speed: (min=263.549; avg=252860.427; max=6493506.494)bits/s
rngtest: FIPS tests speed: (min=45.960; avg=84.689; max=87.094)Mibits/s
rngtest: Program run time: 79320378 microsecondsalso tried this command : sudo rngd -f
and the output was:
too many FIPS failures, disabling entropy sourcetoo many FIPS failures, disabling entropy source
No entropy sources working, exiting rngd
so .. do i have a CPU Problem ? and how do Math.random() work ? does it depend on hardware rnd ? or a kernel /dev/random ?
-
@MostafaGamal said in Problem with Math.random():
Yes, i have the same processor as in the forum post : AMD Ryzen 7 3700X 8-Core @ 16x 3.6GHz
if updating BIOS is the solution ... which BIOS version shall i install ? (My MotherBoard is : Gigabyte B450 Aorus Pro Wifi)Get the latest version from your motherboard's support website.
so .. do i have a CPU Problem ?
Probably, since it's not providing entropy.
and how do Math.random() work ? does it depend on hardware rnd ? or a kernel /dev/random ?
I don't know the internal details, but good modern RNGs should always depend on hardware.
-
-
i've tried to run
quint32 rnd = QRandomGenerator::global()->generate();
in a seperate new project for testing too and found the following:
rnd value is always constant : 1988610280i think It leaves no doubt that it is CPU issue .. right ?
-
@MostafaGamal said in Problem with Math.random():
quint32 rnd = QRandomGenerator::global()->generate();
Did you run it more than once during the same run? Did you specify a seed value? What seed value?
-
@fcarney
no i didn't provide a seed value.but i ran it more than once, Yes about 9 times
and the same value every time.btw .. when tracing my UUID Function a new number is generated every 58 tick.
for ex: if i did a for loop 58 times, a new value is generated.
-
@MostafaGamal said in Problem with Math.random():
but i ran it more than once, Yes about 9 times
That is not what I asked:
for(int count=0; count<10; ++count){ quint32 rnd = QRandomGenerator::global()->generate(); qInfo() << rnd; }
Does this produce the same output for all 10 values?
Edit:
I get completely different values on every run. So yeah, there is something wrong. I am also not providing a seed. -
Yes,
The same output every run without a seed.so, yeah something is not correct here. i'll update my BIOS then re-check it again
-
@MostafaGamal You have found a really interesting and annoying problem. Please keep us posted as to the outcome.
-