The rattle inside some spray cans is caused by an object inside the can that helps mix the paint (or other payload) with the propellant inside the can. The propellant forces the paint out of the can, but the propellant and the paint tend to separate over time into two distinct layers inside the can. Bouncing a marble up and down inside the can breaks up the boundary between the two substances and mixes the propellant with the paint, making spray paint actually spray PAINT instead of just plain old propellant.
Is this a worthwhile effort? No. Plain glass marbles can be found at any dollar store (such as The Dollar Tree) in large quantities for much less than the cost of a can of spray paint. I think it’s still worthwhile to know what is inside the mechanical devices we use every day. If you enjoy busting open empty spray cans, you will get a marble for your trouble. Enjoy!