[solved]Ran into an odd bug when I tried to generate random numbers for items

So I am creating a game that will allow the player to craft weapons with random stats. But I am running into a huge issue. I made it to where the numbers generated would print out to the console, but it sets the item stats to the same number as identical items. for example


http://i1116.photobucket.com/albums/k577/jay4842/Capture%201.png

all of these items have the exact same stats.

but in the console it said other wise.


http://i1116.photobucket.com/albums/k577/jay4842/Capture%202.png

I dont know where the problem is, I only set the item stats once, but they all are set to the same number. The numbers only generate a new random number every time the program is compleatly restarted. If you have any idea please help. Thanks!

edit:
This is where the item is set and modified then added to the players inventory


http://i1116.photobucket.com/albums/k577/jay4842/Capture%203.png

This is the getRand(int x) method


http://i1116.photobucket.com/albums/k577/jay4842/Capture%204.png

sorry forgot the code

Well this is entirely a code issue and you posted no code, so we’re not really going to be able to help.

It seems you are modifying/adding the same object each time when you do:

knife = Templates.IronThorn

That was done to see if the same item could have different stats so that each item is unique in its own way. but it only seems to add one single item instead of two similar items maybe?

Make sure you’re clear on the difference between reference and value semantics and which applies here. You might check out this recent thread - it contains links to some articles that cover this.

In short, it looks like all your ‘instances’ are actually just references to the same object, which is probably why they all appear to have the same characteristics.

That was actually it! thank you, I will remember that in the future!