Author Topic: Seedrnd on iphone  (Read 2058 times)

Offline mykyl66

  • Mr. Polyvector
  • ***
  • Posts: 114
    • View Profile
Seedrnd on iphone
« on: 2010-Aug-10 »
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

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10752
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Seedrnd on iphone
« Reply #1 on: 2010-Aug-10 »
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.

Offline jaywat

  • Mr. Drawsprite
  • **
  • Posts: 68
    • View Profile
Re: Seedrnd on iphone
« Reply #2 on: 2010-Aug-10 »
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%

Offline jaywat

  • Mr. Drawsprite
  • **
  • Posts: 68
    • View Profile
Re: Seedrnd on iphone
« Reply #3 on: 2010-Aug-10 »
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.

Offline Slydog

  • Prof. Inline
  • *****
  • Posts: 932
  • KodeSource
    • View Profile
    • KodeSource
Re: Seedrnd on iphone
« Reply #4 on: 2010-Aug-10 »
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:
Quote
RAND_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.
« Last Edit: 2010-Aug-10 by Slydog »
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Offline jaywat

  • Mr. Drawsprite
  • **
  • Posts: 68
    • View Profile
Re: Seedrnd on iphone
« Reply #5 on: 2010-Aug-10 »
^ what he said :)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10752
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Seedrnd on iphone
« Reply #6 on: 2010-Aug-10 »
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?