I'm making a game where you have to collect coins but i need a way to make it spawn at a random location, can anyone help?
// (1) int x = Greenfoot.getRandomNumber(600); // (2) int x = (int)(Math.random()*600); // (3) int x = (new java.util.Random()).nextInt(600);
java.util.Random rand = new java.util.Random(); int x = rand.nextInt(600); int y = rand.nextInt(600);
Coin coin0 = new Coin(); addObject(coin0, Greenfoot.getRandomNumber(300), Greenfoot.getRandomNumber(200); Coin coin1 = new Coin(); addObject(coin1, Greenfoot.getRandomNumber(300), Greenfoot.getRandomNumber(200); Coin coin2 = new Coin(); addObject(coin2, Greenfoot.getRandomNumber(300), Greenfoot.getRandomNumber(200);