Math.random problem - pulling my hair out

 This works fine on IOS and Android and Win Corona simulator. For some reason it isnt on Windows Phone or Visual Studio Emulator and Im lost.

EDITED .

I have stripped graphics away and have this and its always coming up with 2

M.num=math.random(1,3)

M.bonusGameText.text=M.num

I tried math.random(1,10) and I get 6 every time

I tried math,random(1,100) and I get 55 every time

Weird

Run exact project in Corona simulator and works as it should

Have you tried using math.randomseed at the start?

Before doing any math.random call, do a math.randomseed(os.time()). It’ll make it so the results of math.random are always different.

I haven’t no. I will try that. Never needed to do that before, is this specific for windows phone? - as it does random properly on android and iOS. The weird thing is that on another function math,random works fine. It’s like it on,y wants to work on one instance.

Hi Rob.  You should always call math.randomseed( os.time() ) at your app’s start up.  The reason for this is that math.random() needs a starting point.  On OS-X, it’s using the OS-X library and it could be seeding itself.  Typically on Android and iOS, people who don’t call randomseed() get the same values every run.  I don’t know how this works on Windows and even less on how it works on Windows Phone 8.

Try the randomseed call and see if that changes its behavior.  If not, Engineering will probably need to see what’s happening.

Rob

It worked! That bloody marvelous! You know in almost 3 years Ive never needed that. I’m guessing corona simulator creates a seed automatically then.
(worried now all my Android apps dont randomize !)

Cheers Ragdog and Rob :slight_smile:

I tried math.random(1,10) and I get 6 every time

I tried math,random(1,100) and I get 55 every time

Weird

Run exact project in Corona simulator and works as it should

Have you tried using math.randomseed at the start?

Before doing any math.random call, do a math.randomseed(os.time()). It’ll make it so the results of math.random are always different.

I haven’t no. I will try that. Never needed to do that before, is this specific for windows phone? - as it does random properly on android and iOS. The weird thing is that on another function math,random works fine. It’s like it on,y wants to work on one instance.

Hi Rob.  You should always call math.randomseed( os.time() ) at your app’s start up.  The reason for this is that math.random() needs a starting point.  On OS-X, it’s using the OS-X library and it could be seeding itself.  Typically on Android and iOS, people who don’t call randomseed() get the same values every run.  I don’t know how this works on Windows and even less on how it works on Windows Phone 8.

Try the randomseed call and see if that changes its behavior.  If not, Engineering will probably need to see what’s happening.

Rob

It worked! That bloody marvelous! You know in almost 3 years Ive never needed that. I’m guessing corona simulator creates a seed automatically then.
(worried now all my Android apps dont randomize !)

Cheers Ragdog and Rob :slight_smile: