Adding given number of objects to an area using Python
The devil might be in the detail.. but here's a base case of using a Particle System to scatter objects on a given area.


Create / Duplicate a face representing the area you want scattered with the objects
Create the object you want to be scattered.
In its Particle Settings tab, set the face to be a particle emitter.


There are lots of settings for particle emission, but most of them are self-explanatory, maybe after a bit of trial and error. Here are my settings for this example, trying to keep everything simple to begin with, everything else at default:



All the particles are emitted on frame 1, and have a lifetime of 1, so you have to be there on the timeline to see them.



This is the rotation setting that works for me, with my scattered object ('Cylinder') created with its local Z along its length. 

Depending on what you want, at any stage, the particles can be made into real instances of the scattered object by hitting Convert in the emitter's Particle Settings modifier (in its modifier stack)

Be aware that if you copy the emitter, it will share the particle system with the original. As with other kinds of shared Data-Blocks in Blender, you can make it unique to the user by clicking the digit indicating the number of users under the list of Particle Settings at the top of its Particle Settings tab