Spontaneous knotting of an agitated string