In the Windows version 1.25-50d, RANDOM(n%) sometimes returns n%, when the 1.26 documentation states that it returns 0..n%-1. Do I need to fall back to RAND(0) MOD n% and possible bias? Seen in Winblows 10 and H8.1. I do not see the problem on Android 5.1.1 using the 1.25-50 APK. Thanks!
' RandomizeClri%,j%,k%Fori%=0To499999j%=Random(@CLng%(666))!ForcedatatypingIfj%>=666ThenPrinti%,j%Inck%ElseIfj%<0ThenPrinti%,j%EndIfNexti%Printk%/i%End' My Word VBA macro monkey programmer/analyst wannabe-ness is showing!DefFnCLng%(n%)=n%
Last edit: Yet Another Troll 2019-06-03
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This appears to fix it when Max is an integer but perhaps not when Max is floating point or complex.
Is RANDOM's behavior when Max is negative by design or accidental?
The difference is that WINDOWS uses a 15 bit random generator only and linux a 31 bit randlom generator. That means, one out of 32768 random values will be equal to the argument of the randlom function on WINDOWS and on linux only one out of 2147483648 on linux (and Android).
🎉
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I can think of a quick fix which prevents the value beeing the argument of RANDOM(). And yes, RAND is affected, too. However, I cannot make WINDOWS random generator have a higher resolution.
This fix is now in 1.26-54
🎉
1
Last edit: Markus Hoffmann 2019-06-05
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In the Windows version 1.25-50d, RANDOM(n%) sometimes returns n%, when the 1.26 documentation states that it returns 0..n%-1. Do I need to fall back to RAND(0) MOD n% and possible bias? Seen in Winblows 10 and H8.1. I do not see the problem on Android 5.1.1 using the 1.25-50 APK. Thanks!
Last edit: Yet Another Troll 2019-06-03
This appears to fix it when Max is an integer but perhaps not when Max is floating point or complex.
Is RANDOM's behavior when Max is negative by design or accidental?
If the argument (arg) to RANDOM() is negative, a random number between ]arg,0] should be returned.
Hm, interesting point. The Result of yout program above running under linux is 0.
However, the WINDOWS version giles a lot of:
38723 666
67538 666
70001 666
72302 666
76270 666
...
Last edit: Markus Hoffmann 2019-06-04
This program shows the difference. The last line is 10 0 on linux and 10 6 on WINDOWS. So a tiny fraction of the random number is the argument.
The same problem with RND():
Last edit: Markus Hoffmann 2019-06-04
The difference is that WINDOWS uses a 15 bit random generator only and linux a 31 bit randlom generator. That means, one out of 32768 random values will be equal to the argument of the randlom function on WINDOWS and on linux only one out of 2147483648 on linux (and Android).
I have addressed that issue in the manual now, since I believe I cannot really fix it in X11-Basic. Thanks for mentioning it!
Could this possibly affect RAND too, perhaps with an over/underflow/wraparound to 0x80000000?
I can think of a quick fix which prevents the value beeing the argument of RANDOM(). And yes, RAND is affected, too. However, I cannot make WINDOWS random generator have a higher resolution.
This fix is now in 1.26-54
Last edit: Markus Hoffmann 2019-06-05