Making random numbers within an array?

I am trying to use this code to define a new random to a member of an array but it is not working :frowning: any ideas?

ballupdate(GameScreen.sballX[0]);

this is a much simplified version


	public void ballupdate(int apple) {
		apple = random.nextInt(600) + 1;
	}

apple is a parameter, which is a local variable. You’re writing to it, doing nothing with it, and returning. You need to return the value and assign it to the proper array position in the caller.

This is fairly intro-level stuff – have you gone through the java tutorial on oracle.com yet?

how would i do that?


GameScreen.sballx[0] = random.nextInt(600) + 1;

or


public int ballupdate() {
    return random.nextInt(600) + 1;
}
[...]
GameScreen.sballx[0] = ballupdate();

Both give exactly the same results.


public void ballupdate() {
    return random.nextInt(600) + 1;
}
[...]
GameScreen.sballx[0] = ballupdate();

Void function returning an int? :o

::slight_smile: Edited, fixed :slight_smile: