I'll let CAPT MJ weigh in as she probably is most informed on this issue.
My sense is that there is some method to the madness. For example, they don't want the entire crew team to be in one company. They don't want half the company to be from the same state. They want the prior enlisted spread out among the brigade
The above said, I'm not sure they get down to the individual plebe. For example, let's say there are 35 prior enlisted. That would be about 1 per company. I'm assuming they just assign those randomly as opposed to saying, former Petty Officer 3/C Jones will go to X company and former Seaman Smith will go to Y company.
And I don't think there is any effort to make PS roommates "compatible." As noted, they are almost never from the same state.
After PS -- and especially after plebe year -- mids have much more choice in terms of roommates. The one fixture is that (with certain exceptions), your roommate must be from you company and class.