-5

Am designing wumpus hunting program using java. Where i can include three gold, 3 pits, one wumpus, one player. and the position of the game item should be random generator.How to generate random characters in 2d array . How to specify the range for the characters in java. Thanks.

1 Answers1

0

You can use the method random.nextInt() to generate a random number for the position. If you want to generate a random character you should use : (char)(random.nextInt(max-min)+min). Where the max and min value are the ascii code of the max and the min char. If you only want to generate a char in some char you should create an array with these character and use yourArray[random.nextInt(yourArray.length-1)+1];

Edit : You have to create the object random at the beginning of your code. Random random = new Random();

Dinidu Hewage
  • 2,169
  • 6
  • 40
  • 51