I'm an alum. I'll speak on how it was in the late 90s...I imagine it hasn't changed much, but who knows?
Cadets are assigned to a room Rat year with 2, 3, or 4 other people. You room with people in your company, and have no say over who they are. Attrition may cause some of the people to leave your room, and it may allow for other people to move in when that happens. As tpg has alluded, this is dependent on the rooming situation in Barracks at the time stuff happens. During my Rat year, I was initially assigned to a room on the third stoop, which is traditionally where sophomores live. I didn't even spend one night there, as I was assigned to a room on the 4th stoop before dinner on the first day (Room #400 in Old Barracks, in case anyone cares). A dude quit on the first day, and there was a spot for me up there.
I was in my 4th stoop room with 4 other cadets initially; however, one quit right after Hell Week ended, and we were down to four total cadets in the room (myself and three others). They did not move another Rat into the room for the rest of the year. I do know of some of my BRs who had roommates added during the year for one reason or another, although it wasn't all that common. It could happen, though.
As an upperclassman, you get to pick your roommates. They do not have to be from the same company, which is the case for Rat year. You live on the stoop assigned to your class. 3rds (soph.) on the third stoop, 2nds (juniors) on the second stoop, firsts (seniors) on the first stoop. Room assignment is handled by class officers, or at least it used to be (the Class Historian was in charge of room assignments in my day).
Hope this helps.