Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Anyone notice problems with the random number generator?

Author
Message
ManOfActionTM
13
Years of Service
User Offline
Joined: 16th May 2011
Location: Sahuarita, Arizona
Posted: 24th Feb 2012 20:00
I didn't have any problems with the iPhone version of my software, but now I notice no randomness at all working with the iPad version.

I'm not seeding it at all.
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 27th Feb 2012 18:11
I'll make sure future versions randomize their seeds internally so multiple runs of the program will produce different results. This means that if you want to keep the existing functionality of the same seed every run you will need to use SetRandomSeed() with a constant value. The random number generator is built into AppGameKit so a particular seed will produce the same sequence of numbers on every platform.
ManOfActionTM
13
Years of Service
User Offline
Joined: 16th May 2011
Location: Sahuarita, Arizona
Posted: 27th Feb 2012 18:15
What I ended up doing (since I am using T2) was use arc4random and that cleared up the problem (I think).

This also started to show up on my iPhone version as well. Though everything is extremely intermittent. Sometimes it works fine, other times you get the same 'roll' every time. Not sure what's up with that.

Glad to see TGC is on the case and fixing it!
XanthorXIII
AGK Gold Backer
13
Years of Service
User Offline
Joined: 13th May 2011
Location:
Posted: 28th Feb 2012 00:39
And no one believed me that the Random Function wasn't working very well. I even wrote this function to fix the problem which works very well.

Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 1st Apr 2012 01:51
Quote: "I'll make sure future versions randomize their seeds internally"


Will this be fixed for the "7" release?

Right now, using



in the windows player causes the same set of random values to be used every time the program is run, which I guess is to be expected, since timer() is relative to when the program starts.

But using that statement and broadcasting to my iPad/iPod Touch/Kindle Fire causes a different set of random values each run. I guess the AppGameKit Player takes a random amount of milliseconds to start up on those devices, hence the timer() values?

With NO SetRandomSeed statement, the other devices all fire up the program with the same set of random values. So, I'm hoping this gets fixed in the next update.
LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 1st Apr 2012 20:53
The only sure fire way to have true random results is to introduce a human element. I often generate the seed value after the user has pressed a button or moved on from the title screen, or in the new build 107, use the GetTime() value.

I drink tea, and in my spare time I write software.
basjak
14
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 1st Apr 2012 21:56 Edited at: 1st Apr 2012 21:57
I got better results when adding fast incrementing number within a loop [1, 2^32]
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 2nd Apr 2012 01:28 Edited at: 2nd Apr 2012 01:29
Okay, here's what I'm doing...



I use this once at the beginning of the program, then again when the player makes a valid move in the game. Valid moves don't occur too quickly, so I'm not calling timer() very often. By just using the decimal part of the timer value, I get a seed that cycles very quickly, instead of one that is tied to how long the game has been running.

It's working well so far.

Login to post a reply

Server time is: 2024-11-23 07:46:49
Your offset time is: 2024-11-23 07:46:49