There have been similar things discussed on here before…
https://discourse.mcneel.com/t/script-to-fill-void-with-different-sized-squares/113066
@laurent_delrieu is your man.
The example you show is patterned rather than random so I would start thinking about how to describe the logic behind the pattern that you want.