It depends on the state. For example, Massachussetts has semi-open primaries. If you're registered R and show up at the primary, you get an R ballot. If you're registered D, you get a D ballot. If you're registered "Unaffiliated", they ask you which ballot you'd like. That would be something like 55% of MA voters, last I checked.
Looking at https://en.wikipedia.org/wiki/Open_primaries_in_the_United_S... it looks like 17 states have completely open primaries. 4 more are like Massachusetts. 3 more have open or semi-open primaries on the Democratic side only.