Re: Randomizing gun sprites.
As far as I know, there's no way to modify the sprite directly or mess around with an HDFirearm's frame using Lua.
You could try using an attachable that has the different sprites and the gun is a plain rectangle or something, just to serve as something to get shot at.
There isn't any trickery needed to change magazine sprites, so that part is at least easy.