Re: Using threads to affect probability
Just a slight development:
Here's my run() method:
public void run() {
while( true )
{
try {Thread.sleep(1000); } //sleep for 1 second each cycle
catch (java.lang.InterruptedException e){break;}
int randomDelivery = letters.nextInt(10); //get a random number
between 0 and 10
int placeSize = buildings.size(); //get the size of the
destinations array
if (randomDelivery <= 4) { //evaluates to 40% odds of success
int randomLocation = new Random().nextInt(placeSize); //pick a
random number out of the array
deliveries.add((Sprite)buildings.get(randomLocation)); //add
the randomly picked sprite to the array
}
}
}
A toString representation of the size of the deliveries array prints 9
right away (doesn't count up or anything), which is obviously linked to
the "nextInt(10)". I looked through my logic and I'm unsure where I
messed up.
To everyone speculating the nature of the task - this section is
optional anyway, I'm just gonna interpret it as meaning "if number <0.4
receive mail, otherwise do nothing" as someone above stated. As for
dealing with it all, there are "delivery" Sprite objects that we're
supposed to experiment with (using varying speeds etc) to balance the
load.. once I get deliveries working.