I am trying to make coordinates for 25 objects, however i want them to be randomized each time.
Here is my current code:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.*; /** * Write a description of class CircutBuildAndDisplay here. * * @author (your name) * @version (a version number or a date) */ public class CircutBuildAndDisplay extends Actor { //public int one = rand(30) - rand(4) + rand(100); public World whichworld; public boolean dothisonce = false; int[] ints; int[] ints2; World cw = (CircutWorld) getWorld(); public CircutBuildAndDisplay(World world) { whichworld = world; } public CircutBuildAndDisplay() { } /** * Act - do whatever the CircutBuildAndDisplay wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if(getWorld() instanceof CircutWorld) { cw = (CircutWorld) getWorld(); if(!dothisonce) { ints = new int[25]; for(int l = 0; l < 24; l++) { ints[l] = (rand(5) + 2); } ints2 = new int[25]; for(int l = 0; l < 24; l++) { ints2[l] = (rand(5) + 2); } for(int l = 0; l<24; l++) { if(l < 2) { cw.addObject(new Light(),ints[l]*64,ints2[l]*64); } else if(l < 8) { cw.addObject(new Wire(),ints[l]*64,ints2[l]*64); } else if(l < 12) { cw.addObject(new Resistor(),ints[l]*64,ints2[l]*64); } else if(l < 15) { cw.addObject(new Diode(),ints[l]*64,ints2[l]*64); } else if(l < (24 - (CircutWorld.level/2))) { cw.addObject(new EmptyCircuitArea(),ints[l]*64,ints2[l]*64); } } dothisonce = true; } } } public int rand(int i) { int i2 = Greenfoot.getRandomNumber(i); return i2; } }