Evenly filling spaces for a specific average value Imagine I have $N$ spaces.  Each space can be empty, or occupied.  Given a fixed point value $x$ between zero and one, I would like to evenly populate the $N$ spaces such that $\frac{N_{\text{occupied}}}{N}$ is approximately equal to $x$.  The purpose of the even distribution is such that the average rate of encountering occupied spaces when traversing the spaces follows $x$.
I understand that $\left \lfloor{N \cdot x}\right \rfloor$ will give me the number of spots to fill.  But how do I algorithmically distribute them most evenly within the $N$ spaces?  Is there any way to do this "cleanly"?
I've considered doing this with a boolean pseudorandom number generator with mean $x$, but I'm worried that wouldn't give optimal reliability and precision.  Ideally the solution would not be very computationally intensive.  Thank you so much.

Here is one way to do it. Generate the list of $N$ numbers $$\lfloor 0.5\rfloor, \lfloor x+0.5\rfloor, \lfloor 2x+0.5\rfloor,\dots,\lfloor (N-1)x+0.5\rfloor,$$ where $\lfloor\cdot\rfloor$ is the greatest integer function. Then “fill” box $k$ when $\lfloor kx+0.5\rfloor>\lfloor (k-1)x+0.5\rfloor$.
Note that this is equivalent to drawing the straight line from $(0,-0.5)$ to $(N-1,(N-1)x-0.5)$ on an integer grid and “filling” each column if the line passes through a horizontal grid line in this column. In the picture below, the line and it’s “floor” are drawn. You’d fill the boxes for the leftmost $x$-value of each segment of the floor function (orange), or boxes $2,5,9,12,15,19,22,25,29$, if $x=0.3$ and $N=30$.

This is like the “anti-aliasing” problem in computer graphics, where one needs to draw a slanted line using square pixels.
