/execute as @e[type=item,nbt={Item:{tag:{author:"randombook"}}},limit=1] run data modify entity @s pages[0].text set from entity @e[tag=randomizer,limit=1] <nbt path to random number>
for put a location to get the random number from an entity with the tag 'randomizer', using nbt path format. One way you could do this is by adding ,sort=random
after the text limit=1
and having multiple entites with the tag 'randomizer' with different names or some other tag that supports integers and doesn't change, and specifying the path to said entity. Once you decide on how you want to do this I can help with the nbt path stuff if you want. I'm just not sure on the best way to do this part so I will leave it open ended
If you want to modify the text of a book in a chest to a random value:
Note: work in progress, I have not included a source of randomness
/data modify block <x> <y> <z> Items.[{tag:{author:"randombook"}}].tag.pages[0] set from <source>
(here's the tricky part, the source of randomness.)
To include a source of randomness for the book in chest option, there are a few things you could do. It is more complicated since I can't get the .text part at the end to work since it seems to be a string with NBT data inside. Seems to have stopped working for the first solution too? The best option I could think of right now is giving multiple armor stands (each possible combination on 1 page needs its own armor stand) a custom NBT tag such as random:'{"text:"<numbers here>"}'
and remove the single quotes '
if they cause problems. If you could access NBT data from within those single quotes you could add multiple sections to the page for near unlimited randomness.
Anybody know how to access the NBT data inside 'single quotes?'