Bug 139985 - Problem with rept() in combination with randbetween.nv()
Summary: Problem with rept() in combination with randbetween.nv()
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
7.0.2.2 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Cell-Formula Calculate
  Show dependency treegraph
 
Reported: 2021-01-28 23:17 UTC by Joachim Kreutzer
Modified: 2023-09-02 19:43 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:


Attachments
Calc-file, which shows in cell A1 the rept -problem (8.44 KB, application/vnd.oasis.opendocument.spreadsheet)
2021-01-28 23:22 UTC, Joachim Kreutzer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Joachim Kreutzer 2021-01-28 23:17:03 UTC
Description:
Cell A1: =REPT("a";B1)
Cell B1: =RANDBETWEEN.NF(1;10)

Safe and open the file and you see, the A1 the error in A1

Steps to Reproduce:
1. Cell A1: =REPT("a";B1)
2. Cell B1: =RANDBETWEEN.NF(1;10)
3. Safe and open the file and you see, the A1 contains wrong number of 'a'.

Actual Results:
Example
Cell B1 contains 8
Cell A1 contains "aa"

Expected Results:
Cell B1 contains 8
Cell A1 contains "aaaaaaaa"


Reproducible: Always


User Profile Reset: No



Additional Info:
While RANDBETWEEN.NF is recalculated by opening the calc-file, the cell with rept won't be updated.
Comment 1 Joachim Kreutzer 2021-01-28 23:22:32 UTC
Created attachment 169253 [details]
Calc-file, which shows in cell A1 the rept -problem

Please open the file and you see the problem immediatly in cell A1 versus A2.
Comment 2 Julien Nabet 2021-01-29 16:44:04 UTC
Assignee field is for those who work on a bug fix, is it your intention or just a mistake?
Also don't confirm your own bug.

On pc Debian x86-64 with master sources updated today, I got the same behavior as reported. Now I'm not an expert but not sure if it should really change each time you open Calc.

Let's wait feedback from other QA people or Calc experts.
Comment 3 m_a_riosv 2021-01-29 18:37:59 UTC
In A2 NOW() function that it's volatile forces the calculation.
But not clear to me why REPT() is not calculated and RANDBETWEEN.NV() is.
And not matter in which cell REPT() is put.
Deleting the cell with NOW() ind, doesn't solve the issue, even more in this case [F9] only works if you are in the cell with REP().

Looks to me like some kind of bug.
Comment 4 BogdanB 2021-01-30 06:36:25 UTC
It is working with Data - Calculate  - Recalculate Hard, OR Shift+Ctrl+F9, but I don't say that is not a bug. Maybe it should be automatically recalculated.


Version: 7.0.4.2
Build ID: dcf040e67528d9187c66b2379df5ea4407429775
CPU threads: 4; OS: Linux 5.8; UI render: default; VCL: gtk3
Locale: ro-RO (ro_RO.UTF-8); UI: en-US
Calc: threaded
Comment 5 ady 2023-09-02 19:18:18 UTC
NOW() is a volatile function; REPT() is not.

RANDBETWEEN.NV() is not a volatile function either, but it is recalculated under certain circumstances such as when opening the file (see help content).

You could modify menu Tools > Options > LibreOffice Calc > Formula > Recalculation on File Load, or manually use Data > Calculate > Recalculate Hard ([CTRL]+[SHIFT]+[F9]), but these might not be enough when sharing the file.

Or instead of
=REPT("a";B1)

...you add some volatile function. For instance (just as a generic example):
=REPT("a";B1)&T(NOW())

If you have to use this method on multiple cells, you could have:
C1: =T(NOW())
A1: =REPT("a";B1)&$C$1

...and re-use "&$C$1" (or "+$C$1" on numeric functions/cells) on each relevant cell.

These methods would force the recalculation on that/those specific cell(s).

Each alternative has its own pros and cons.

Another possibility would be to use the RANDBETWEEN.NV() function as the second argument of REPT(), but that would be only useful when there are no other cells that would need to depend on the same resulting value of the same RANDBETWEEN.NV() function. When multiple cells must depend on the _same_ result of the RANDBETWEEN.NV() function, this alternative would not be a valid approach.
Comment 6 ady 2023-09-02 19:28:50 UTC
OTOH, RANDBETWEEN() _is_ a volatile function, so you might just use that instead of RANDBETWEEN.NV().
Comment 7 ady 2023-09-02 19:43:30 UTC
There is one additional POV for this report; which is the possible need/desire to recalculate RANDBETWEEN.NV() only once when the file is loaded (or for whichever event the function is normally recalculated), and _then_ recalculate any dependent cells.

I guess that such approach would make this an enhancement request for some additional option or some kind of new variant on RANDBETWEEN.NVxx().