The best prevention is preventing criminal behaviour. By taking care of mental health, community, opportunity and support.
Not sure if violent acts are entirely random, I have not enough expertise on that. Currently I assume most acts of violence are not entirely random; and if they are, they are a mental/medical/neurological illness. And it might be perfectly normal to be dispositioned to be like this, but it would still be a problem.