How do I fill an area with randomly sized cylinders?

I am trying to procedurally place prefabs with random scale on a plane. I hope to fill the space with prefab cylinders of random diameter that are perpendicular to the plane then spawn the prefabs from those cylinders. The cylinders provide a buffer and are a way to ensure there is sufficient space between them. Right now the best idea I’ve had is to pick a random size then move the spawner around until it isn’t touching anything, but it’s unreliable, sometimes double spawning, sometimes not spawning when I think it should.

Below is a general idea of what I’m looking for. If I can get that, I can work out the rest.


Also, here’s a 2 of some experimenting I’ve done, using OnTriggerEnter and OnTriggerExit to test whether there would be overlap, but as you can see it’s unreliable and I’m still not sure how to fill the area without obvious patterns.

What you’re looking for is ‘Bin Packing Problem’ that’s a good C# implementation of it, which won’t be hard to wrap for unity.