Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. ## Random Number Arrays

Ok so im trying to create two arrays of different random numbers, the problem is both arrays have exaclty the same numbers, now i have tried using one Random and the setting different seeds before generating the numbers but this does not help.

Heres the code

```Random rnd = new Random();

//Create tempchannels for scene1
for(int i=0;i<=511;i++){
tempChannels[i] = rnd.nextInt(255);
}
scene1 = new Scene(tempChannels);

//Create tempchannels for scene1
for(int i=0;i<=511;i++){
tempChannels[i] = rnd.nextInt(255);
}
scene2 = new Scene(tempChannels);

compScene1 = scene1.getChannels();
compScene2 = scene2.getChannels();```

2. ## Re: Random Number Arrays

I bet if you defined two different arrays to pass into your scenes you wouldn't have this problem

3. ## Re: Random Number Arrays

Thats great it worked, but now to be awkward i want to understand why my original logic didnt work. If im setting all 512 parts of the array to a random number then assigning that to scene1, then i overwriting the array and assigning that to scene2 why did the numbers come out the same? The random number seed is set at the start so once it has generate the first 512 numbers the second 512 wuld essentially be continuing from the pointnit left off. But it seems to be restarting from the same seed point, if that makes sense.

4. ## Re: Random Number Arrays

im setting all 512 parts of the array to a random number then assigning that to scene1, then i overwriting the array and assigning that to scene2
How much arrays do you manipulate during this operation?

5. ## Re: Random Number Arrays

Three arrays mainly. One to hold the random numbers generated that is then passed into a new object of scene, ie scene1. This same array is then has its values overwritten and passed to a new object of scene ie scene2 I then use two more arrays to read the arrays from the each object ie scene1 and scene2

6. ## Re: Random Number Arrays

Do you remember, that you pass to the methods not the arrays themselves, but merely references to the array location in JVM heap?

7. ## Re: Random Number Arrays

Of course , how silly of me to make such a mistake, cheers for the help