If I set the destination X and Z values using a reference instead of a copy, the Random struct doesn’t seem to update after each NextFloat call.
For instance, if I set the values like this…
destination.Value.x = randomArray[nativeThreadIndex].NextFloat(0f, 100f);
destination.Value.z = randomArray[nativeThreadIndex].NextFloat(0f, 100f);
…then the x and z values are identical (eg, [31.52221, 0, 31.52221] )
However, when I set X and Z by copying the Random and then copying back into the array (like the instructor), then it works as expected (again, like the instructor’s):
var random = randomArray[nativeThreadIndex];
destination.Value.x = random.NextFloat(0f, 100f);
destination.Value.z = random.NextFloat(0f, 100f);
randomArray[nativeThreadIndex] = random;
My question is why? Why is the behaviour different?
If I’m using the Random struct through a reference, I would expect it to be operating equivalently to a copy of it.
(Note, I’m using the same packages as the instructor in the course)