How to insert a field of a random integer in the range 5 to 20?

Hello,
In LibreOffice Writer, how to insert a field of a random integer in the
range 5 to 20? This random integer changes every time I open the document.
Thanks and regards.

o In a spreadsheet document, enter =INT(RAND()*16)+5 in a cell.
o Save the document.
o In your text (Writer) document, go to Insert | Object > | OLE Object... .
o Select "Create from file".
o Tick "Link to file".
o Click Search... and browse to and open your spreadsheet file.
o Position and resize the inserted item as necessary.
o Each time you open the text document, accept the offer to "Update all links?". Provided the spreadsheet file is closed, the formula will be recalculated each time.

An alternative is considering whether to construct your entire text document in the form of a spreadsheet.

I trust this helps.

Brian Barker

Hi,

Hello,
In LibreOffice Writer, how to insert a field of a random integer in the
range 5 to 20? This random integer changes every time I open the document.

https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=16418

will give you a start if you want to insert that number into a footer,
but it will probably not produce a different number on each page unless
you use different page style for each one.

You would need to bind the macro to execute to the OnOpen event of the
document in order for the number to be recreated each time you open it.

Alex

Thanks Brian.
I created a Libre Office Calc spreadsheet with a table like this:

Rand2DiG 91
Rand3DiG 725
Rand4DiG 5869
Rand5DiG 61431
Rand6DiG 872247

where the 2nd column formula are defined like this:
=ROUND(RAND()*89)+10
=ROUND(RAND()*899)+100
=ROUND(RAND()*8999)+1000
...
The 1st column is just a "comment", to remind me the purpose of the
spreadsheet.

Following your solution I get the entire table (2 col. x 5 lines) in my
Writer document. But I want to insert only the content of one of the second
column (the random interger), the value only without any text/cell format
from the spreadsheet document. The insert position format in the Writer
document should be use on this inserted value.

So, *how to insert only the value of 1 cell*?
Thanks and regards.

I created a Libre Office Calc spreadsheet with a table like this:

Rand2DiG 91
Rand3DiG 725
Rand4DiG 5869
Rand5DiG 61431
Rand6DiG 872247

where the 2nd column formula are defined like this:
=ROUND(RAND()*89)+10
=ROUND(RAND()*899)+100
=ROUND(RAND()*8999)+1000

Incidentally, these formulae may not do exactly what you want. RAND()*89 gives a number in the range 0 to 89 and when you ROUND it you get an integer in the range 0 to 89, but zero and 89 are only half as likely to occur as all the other numbers. Only zero to a half produces zero, but a half to one-and-a-half - twice as likely - produces one, and so on. When you have added 10, it's 10 and 99 that are each half as likely as the rest. If you want a uniform distribution, try something like =INT(RAND()*90)+10 etc.

Following your solution I get the entire table (2 col. x 5 lines) in my Writer document. But I want to insert only the content of one of the second column (the random integer), the value only without any text/cell format from the spreadsheet document. The insert position format in the Writer document should be use on this inserted value. So, *how to insert only the value of 1 cell*?

One obvious way would be to create five separate spreadsheets; then you wouldn't need the internal labels and each spreadsheet could contain just its one significant cell.

Alternatively:
o Copy the relevant cell in the spreadsheet.
o Paste it into the text document, but using Edit | Paste Special... (or right-click | Paste Special... or Ctrl+Shift+V) instead of ordinary Paste.
o In the Paste Special dialogue, select "DDE link".

Something like this would also work for your earlier problem, in fact. The only difference is that with OLE you can edit the linked document from the target one, whereas with DDE you cannot. In this case, it would mean you could edit the spreadsheet contents from within the text document. But you wouldn't want to do that in these scenarios.

I trust this helps.

Brian Barker

In Word (2013) it is possible to insert two nested fields with the following definition:
{ = ROUND({ TIME\@\"ss" \* MERGEFORMAT }/4+5;0) }

The 'inner' field results in the seconds of the current time,
this is devided by 4, resulting in a number between 0 and 15, and finnally 5 is added.

I was unable to reproduce this in LibreOffice... ;(

Is anyone be able to do this?

The advantage of this is that you do not need a macro.

Here's a start:
o In the first cell of a table, go to Insert | Fields > | Other... | Document.
o Under Type select Time.
o Under Select, select Time. (Note that "Time" in the earlier Fields menu is actually "Time (fixed) and not what you want.)
o Click Insert. (I don't think it matters what Format you select.)
o Put the cursor into another cell and press F2.
o Complete the formula in the Input Line: =((<A1>*100000-<A1>*100000 round 0+0.5) round 2)*100 and click the green arrow.

I think that gives you an unpredictable two-digit number, but you'd better check the maths. The remainder of the calculation is left as an exercise for the reader!

I trust this helps.

Brian Barker