You will never prevent a random attack, but you can limit them. Don't keep money on you. Keep money in the bank and try to keep your income to a minimum. Most people attack for the money!