Math.random on Android

#1

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!

0 Likes

#2

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

0 Likes

#3

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.

0 Likes

#4

@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:

0 Likes

#5

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

#6

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

0 Likes

#7

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


Thank you!

0 Likes

#8

Works fine on ARM64 :+1:

0 Likes

#9

Thanks a lot!

0 Likes