Generation of unique user_id for session management

2 views
Skip to first unread message

jaxom

unread,
Oct 24, 2011, 4:06:54 PM10/24/11
to jacl-discuss
Hi Stuart,

just out of curiousity: Where did you get the formula of generating
your user_id from?

/* GENERATE UNIQUE USER ID FOR SESSION MANAGEMENT */
sprintf(user_id, "%d-%d",
(1 + (int)((float)58408 * rand() / (RAND_MAX + 1.0))),
(1 + (int)((float)256 * rand() / (RAND_MAX + 1.0))));

I do not understand this!:-)

Why not simply for example "sprintf(user_id, "%d-%d", rand(),
rand());"?

Thanks for explaining!
Thomas

Stuart Allen

unread,
Oct 24, 2011, 7:42:16 PM10/24/11
to jacl-d...@googlegroups.com
Hi Thomas

To be honest, I don't really remember! :) I don't think there was any
amazing magic to it other than getting a integer number large enough
to have a good chance of being unique. A hash of the source IP address
and user client might have been a better choice in hindsight. Ideally
something like the system you implemented for you multiplayer JACL is
best where the user creates a username and password. That way the
system guarantees that they are all unique and to player can pretend
to be another user.

Regards,
Stuart

--
http://dangarstu.tumblr.com

Reply all
Reply to author
Forward
0 new messages