I think this is more of a C# question than a monogame question
I have a class called Tile
I have a list of those called Tiles
in each Tile’s constructor, there’s a random generator to make each tile a different frame.
However, it doesn’t seem to be working properly. It only makes it one frame, it doesn’t pick a new random frame for each Tile, it just picks one and does that for each new Tile. what’s wrong here?
Then I define it in the constructor randomly, which works, but it only picks ONE random int for every single Tile in the Tiles list. I want each individual tile to be their own random currentFrame instead of the first one it picks
Looks like you are initialising Random each frame. Remember the Random class is not a true random, for the same time it will always generate the same range.
Move the :
Random rand = New Random();
To the top of the class and that should help. However to make random a bit more random, use a modulus as well, something like (excuse coding from memory)
You are making a new Random class each time and are most likely using the same seed. Explained a bit more here.
Basically you are just using the same initial random number due to the seed being created at the same time.
I am not 100% sure but I feel this is most likely the case but it depends on your implementation. I am assuming you have a loop that calls all those Tile constructors really quickly, so they are all using the same time based seed.
Solution: I suggest starting the Random class just outside the initial loop so it is only initialized once.