Most games implement shotguns as a weapon which fires multiple projectiles at once, but each one with a certain randomization of the angle they leave the actor. In most modern first-person-shooters almost all weapons have at least some spread for every shot they fire to make them less accurate on long range, so the same implementation can be used for shotguns.
Simple implementation: When you want a 10° spread and the player looks into direction 0° vertical and 50° horizontal, the projectiles would leave them in an angle between -5° and +5° vertical and between 45° and 55° horizontal.
Better implementation: Spread the projectiles not in a rectangular but in a circular area around the crosshair of the player.
The perceived reduced efficiency on long range results from the spreading of the projectiles which means that distant and small targets won't be hit by all of them. When you would like to further emphasize this to make your shotgun a pure short-range weapon, you can also reduce the damage of each projectile for every game-logic frame it travels.
In top-down or side-scrolling shooters it is less common to have spread on all weapons because the playing-area is too small for this to make sense, but when you want a weapon like a shotgun this is a different matter and the same technique can be used, just that you don't need to care about the 3rd dimension. Alternatively you could just fire the projectiles in fixed angles Like -6°, -4°, -2°, 0°, 2°, 4°, 6°. In a 2d context it won't look as artificial as in a 3d context and the challenge-gamer will like it, because it reduces chance.