trying to add an item at random time intervals.
I was thinking I need to start when i is equal to arriveTime, once that is met I need to create a new random arrival and add i (otherwise it will not happen again as i is already past arrival. So I add another if, once that is met create new arrival time and add i again. pseudocode seems to make sense, code not so much, any help is appreciated.
ArrayList<Integer> q = new ArrayList<Integer>();
Random r = new Random();
int arrivals = 0;
for (int i = 1; i <= 720; i++) {
int arrive = r.nextInt(4)+1;
if (i == arrive) {
q.add(i);
arrivals ++;
arrive = r.nextInt(4)+1+i;
}
else if (i == arrive) {
q.add(i);
arrivals ++;
arrive = r.nextInt(4)+1+i;
}
}
sorry, arriveTime should be just arrive. ArriveTime does not exist.
edit: To expand from comments. 'i' represents time and I dont want to add a random integer to the list. Rather add the same object at random intervals of 'i'. I was adding the value of 'i' to the list to see at what times the algorithm was adding an item because it didnt seem to be working. Results vary, but it seems to be always single digits that get added to list. Also made updates to code.