Seedrnd on iphone

Previous topic - Next topic

mykyl66

hi,

Currently been testing seedrnd and noticed on pc it works fine but on the iphone no matter what initial seed I give it it always returns the same number. I am using version 7 of glbasic as Im not comfortable using beta software for developing on.

Cheers

Mike R

Kitty Hello

the same "number" or list of numbers?
What are you feeding seedrnd ? GETTIMERALL? That might be the same for every start.

The core function of rnd/seedrnd is the same on all platforms.

jaywat

I'll elaborate on Mike's issue with a quick example. The problem isn't so much with SEEDRND. Rather, it's a difference in how the same code is apparently executing between pc and ipod. Regardless of whether it's 'good' code or not, perhaps you can explain the following phenomenon?

Every time I run this on the PC, I get a nice, big integer that differs every time.
Every time I run this on the ipod I get the same answer for an entire 24 hour period? (today it's 2147483648!).

When seedString$ is the same on both, the type converted integer is different on the PC to on the iPod.

Code (glbasic) Select

theTime$ = PLATFORMINFO$("time")
rawString = SPLITSTR(theTime$,timeArray$[],"- :")
FOR a = rawString-1 TO 0 STEP -1
seedString$ = seedString$ + timeArray$[a]
NEXT
finalSeed% = INTEGER(seedString$)
SEEDRND finalSeed%

jaywat

Oh wait. I think I may have answered my own question, and it's definitely a gotcha to look out for if I'm right!

2147483648 is the maximum of a long integer as far as the ipod is concerned, but my PC is having no problem giving me a bigger number, being 64 bit.

So essentially, it's really an 'error', not a return value on the calculation.

Slydog

#4
Sounds like the value is going out of range.
Perhaps the iPhone is only 32bit, while a PC is 64bit?
2^31 = 2147483648, the max for a signed integer.

I found this in Google:
QuoteRAND_MAX is a constant defined in <cstdlib>. Its default value may vary between implementations but it is granted to be at least 32767.

Gernot, could this constant be changed either for all platforms, or for the iPhone only?
Just a thought, if that is the problem.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

jaywat


Kitty Hello

I'm not using rnd or seed . I use a better rnd algorithm to provide exact the same results on all platforms.
Please check and stdout the platforminfor$("TIME") on Win32 and iPhone. Maybe there's a bug?