The writer holds an obligation, not a right, and that asymmetry is the whole of assignment risk. A holder decides whether to exercise, and may do so for reasons the writer cannot see. A writer decides nothing. The first the writer learns of an assignment is a notice reporting one that has already happened, after which the shares or the cash must be delivered. This is why writing options is not the mirror image of buying them in any respect other than the sign of the premium.
Allocation runs in two steps, and only the second one is discretionary. The clearing corporation matches the exercise to a clearing member with a short position in that series. The member then decides which of its own customers holding short positions is assigned, and FINRA Rule 2360(b)(23)(C)(i) constrains how: "each member shall establish fixed procedures for the allocation to customers of exercise notices assigned in respect of a short position in option contracts in such member's customer accounts. Such allocation shall be on a 'first in-first out' or automated random selection basis that has been approved by FINRA or on a manual random selection basis that has been specified by FINRA." The same paragraph requires the member to "inform its customers in writing of the method it uses to allocate exercise notices to its customer's accounts, explaining its manner of operation and the consequences of that system."
The method is not the firm's private business. Rule 2360(b)(23)(C)(ii) requires the member to report its proposed allocation method to FINRA and obtain prior approval, and forbids changing it without reporting and approving the change. Rule 2360(b)(23)(C)(iii) requires three years of work papers sufficient to establish how allocation is in fact being accomplished. So a writer who wants to know their odds can ask for the method in writing and is entitled to an answer, and the firm has to be able to prove it followed it.
First in, first out and random selection produce genuinely different exposures, which is the practical reason to know which one your firm uses. Under a first in, first out method the oldest short positions in a series are assigned first, so a writer who opened early is assigned before a writer who opened yesterday. Under random selection every short position in the series is equally exposed regardless of when it was opened. Neither is better in the abstract; they simply distribute the same assignments differently, and the difference is invisible until it lands on you.
Assignment can be partial, and this catches people who think of a position as one thing. A writer short five contracts in a series may be assigned on two of them. The remaining three stay open with their original terms. For a covered writer that means part of the underlying is called away and part is not; for an uncovered writer it means the obligation has been partly discharged and partly not, with the rest still live until expiration.
What must happen next is set by rule, not by convention. Rule 2360(b)(23)(D) requires that, as promptly as practicable after an exercise notice is assigned to a customer, the member require that customer to deposit the underlying stock in the case of a call option "if the shares of the underlying security are not carried in the customer's account," or make full cash payment of the aggregate exercise price in the case of a put option, or, where the transaction is in a margin account, to make the required deposit under Rule 4210 and the Federal Reserve Board's regulations. A covered writer already holding the shares has nothing further to deposit; they are simply delivered. A writer assigned on a call who does not own the shares is short the stock and must cover; a writer assigned on a put owes the full strike price in cash.
Early assignment is a feature of American-style contracts rather than an accident. A holder of an American-style equity option may exercise at any time up to expiration. Assignment before expiration is therefore always possible while a short position is open, and the only reliable way to eliminate the exposure is to close the short position by buying the contract back. Rolling, hedging or watching the price does not remove it.