Math.random on Android

Hi!

I have cards game and getting comment from players that cards are not dealt randomly anymore.
I use simple Math.random, I also do untyped __cpp__('srand(time(NULL))'); on the app launch.
Everything seems pretty random on other platforms and my test devices.
Does anyone has any similar problems?

Thank you!

Does time(NULL) print a value that looks unique each time you run the application on Android?

EDIT: Or maybe this: https://stackoverflow.com/questions/18116733/any-function-in-c-or-java-android-could-mess-up-srand

Using Math.random for my card games too(Fisher–Yates shuffle).
But i dont seed with srand.

So far no complains and it looks random every time.

@singmajesty, it’s always different for me, increasing as it has to.
@Vega, Math.random is random for me and 99% of the players, only few have this problem.
My only guess, their devices are hacked.
Unfortunately, those few players complain, but can’t debug for me. :frowning:

Hi,

i recently had this issue on my android device ( Moto Z2 ):
04-23 10:49:32.513 19263 19289 I trace : Main.hx:37: time(NULL)=1556009372
04-23 10:49:32.513 19263 19289 I trace : Main.hx:38: Std.random(1000)=266
04-23 10:49:32.513 19263 19289 I trace : Main.hx:39: Math.random()=0.647641502087936
…
04-23 10:49:54.143 19367 19393 I trace : Main.hx:37: time(NULL)=1556009394
04-23 10:49:54.143 19367 19393 I trace : Main.hx:38: Std.random(1000)=266
04-23 10:49:54.143 19367 19393 I trace : Main.hx:39: Math.random()=0.647641502087936

This happend only in one of my apps, so i tested a bit and found that <architecture name="arm64" /> caused it. Without that line, it works fine. I hope this will help :slightly_smiling_face:

1 Like

Oh shoot!
Thanks a lot @PlutoniumBytes!
Make sense, I have started releasing x64 version recently, but I can’t test it myself.

Hey @PlutoniumBytes, can you try this version of Random, if it works correctly on ARM64?


Thank you!

Works fine on ARM64 :+1:

Thanks a lot!
…

Stuck with same issue, after some tries found out that for ARM64 instead of srand -> srand48 should be used.

Could you verify?