Wrench Posted September 3, 2018 Posted September 3, 2018 hey ya'll. Is math.random broken somehow? if I use math.random(1,5) I get a value >1 all the time. I've also had it giving me very predictable results, even more so than usual for lua. I was gonna have two groups do different things, so I'm calling it like group1thing = math.random(1,5) group2thing = math.random(1,5) even with multiple iterations, they always do the same thing... Carrier Script.
Grimes Posted September 3, 2018 Posted September 3, 2018 Here is the distribution for 1000 checks. 1 and 5 do occur less frequently than others values and that behavior was repeated over several checks. So statistically 1 should occur 20% of the time, in reality it is around 12% of the time. I'll have to check older versions to see if that behavior has changed, but I don't know if it has. 1: 127 2: 235 3: 267 4: 246 5: 125 The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
Wrench Posted September 3, 2018 Author Posted September 3, 2018 Thanks Grimes. So you get a bell curve, Rodger. But I still have the other problem (which I probably didn't draw enough attention to) I always get a result <1, usually like .1257657 regardless of what inputs I use. Carrier Script.
Habu_69 Posted September 3, 2018 Posted September 3, 2018 I have noticed also that math.random appeared to return numbers heavily skewed towards a non-random result. Been wondering about the validity of the random.seed, but that would not account for the bell curve result.
Wrench Posted September 3, 2018 Author Posted September 3, 2018 Habu, Does it return numbers in the right range though? Carrier Script.
Habu_69 Posted September 3, 2018 Posted September 3, 2018 Oh, yes. Always in the right range, but for example I have seen math.random(1,5) return 1 on 5 consecutive occasions, inverse of the bell curve.
Wrench Posted September 3, 2018 Author Posted September 3, 2018 odd, mine is always less than 1. Carrier Script.
Recommended Posts