Generating a Unique ID (for asyc, metrics, whatever)

jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
edited April 2014 in Working with GS (Mac)

Back in Jan I created a tutorial on how to send and receive data using your own server (http://forums.gamesalad.com/discussion/63636/sending-and-receiving-data-using-your-own-sql-server-php-file-and-testproject-included/p1). Since then I've been working on other projects, but this has never been far from my mind. I have a few plans for this:

  1. Create a home grown multiplayer system
  2. Create a way to update gameplay rules/balancing on the fly
  3. Have gameplay from other users influence your game
  4. Gather metrics

All of these require me to somehow track what each player is doing, some will require the player to create an account, but others will not. I needed to come up with a way to quickly and easily create a unique ID for each player that downloaded the game. There are some limitations to this, if the player deleted the game and redownloaded it, the UID would be regenerated. If they restored their backup to a new device, the old UID would still be present. For my implementation, this doesn't really matter.

So this afternoon I set about creating as close to an infinite unique identifier as I could. It's based off of the system time, device height and a seed table of 10,000 randomly generated alphanumeric 10 digit values (thanks to one of my favorite websites RANDOM.org)

Here is a screenshot of my UID Seed Table:

Here is a youtube video showing the types of UID's being generated. As you can see, they are very long, and the chances of two being identical are pretty slim. In the video below, I clicked on the generate button every time it changes .

So what's the code look like?
I'm not going to give it away since I want to make sure my code is unique as possible, but basically I'm constructing a string where I grab the clock time (year, month, day, hour, min, sec, milisec) and then throw the device height somewhere in the middle. I also altered a few sections by tweaking the clock value to random(0-game.Hour) (or something like that). Finally, I grabbed two random cells from the database and pop them in the middle.

Here is a sample expression. It's not exact, but you'll get the idea.

Comments

Sign In or Register to comment.