wixette / isb

Interactive Small Basic (ISB) - Simple scripting language to be embedded in Unity games or shell environments.
https://www.nuget.org/packages/ISB/
Apache License 2.0
24 stars 3 forks source link

Math.Random() and Math.RandomInt() not working correctly #4

Closed ratkingsminion closed 3 years ago

ratkingsminion commented 3 years ago

I'm using the Unity integration demo, and when executing the script with Math.Random() or Math.RandomInt() in, say, a For loop, the functions always return the same numbers. Example:

for y = -3 to 3
x = math.random() * 2 - 1
game.addball(x,4,y)
endfor

The spheres are created in a straight line.

wixette commented 3 years ago

The Math lib generates every random number with a new Random instance. All those instances might share the same seed if they are initiated in a very short time.

Fixed by sticking to a single instance. See https://github.com/wixette/isb/commit/5f0dbb3db0288c8e53a22224aa4bca843d348ec9