正如Apocalisp所写,您可以这样做:import java.util.Random; Random generator = new Random(); int randomIndex = generator.nextInt( 3 ) - 1;