The whole process in a nutshell:
Open Blender. Go into Edit Mode on the default Cube and press ALT+M Merge at Centre. Extrtude on (for instance ) the X-axis. (About as long as one shelf ‘compartiment’…).Select All, Subdivide a bunch of times (to get a bunch + 1 books. I used 23, because I like 23.) and set the Fractal to 0.5 (or something you like, this will randomize how thick the books will be)

. S, SHIFT+X, 0, to straighten out the line. E, Z for height.
2 (Edge Select Mode), select all vertical edges. CTRL+E > Edge Bevel Weight all the way to 1. V, Enter.
In Wreframe Mode, select all vertical Edges. E, Y. Add Bevel modifier set to Width and Weight. Now you should have something like this (in Object Mode):

Re-name the Cube to Book and put it in a new Collection, called Books (for ease of selection later).
Select the Book and in Edit mode: A, P > Separate by Loose Parts. Back to Object Mode and select all the books.
This would be a good time to duplicate the and put them on the shelves (do not rotate the books! Rotate the shelves if necessary).
Then (this is the fun part) go to Object > Transform > Randomize Transform. Adjust the Z-Scale and Y-Location to your liking:
