Qalculate / qalculate-gtk

Qalculate! GTK+ UI
https://qalculate.github.io/
GNU General Public License v2.0
955 stars 71 forks source link

rand(2) alternates #501

Closed Fabian42 closed 10 months ago

Fabian42 commented 11 months ago

I just executed rand(2) 100 times and it always alternated between 1 and 2. The probability of that actually happening randomly is <.0000000000000000000000001‱, so either this is a bug or I should start buying lottery tickets. The same happens with randbetween(1,2). rand(3) and rand(2,2) seem to behave better and rand(2) works properly in the command line, just not 2 values in the GUI program (version 4.8.1).

foreachthing commented 11 months ago

https://github.com/Qalculate/libqalculate/issues/122#issuecomment-451855022

It's random integers, if a value is passed to the function.

Fabian42 commented 11 months ago

I know what it's SUPPOSED to do, but what it actually did was outputting 2 the first time, then 1, then 2, then 1, then 2, then 1 and so on. That's a bug.

hanna-kn commented 11 months ago

The result is only added to the history list if the expression or the result differ from the previous item, thus if rand(2) is calculated 100 times in a row, the results in history will alternate between 1 and 2, but will contain less then 100 values. An exception has now been added for functions generating random numbers.

Fabian42 commented 11 months ago

Aaahh, okay, that explains it! I guess I just didn't notice when I pressed Enter and saw absolutely no change, or subconsciously blamed it on lag or wireless keyboard or so.