Jump to content

How to create 64 bit client id


vinpkl

Recommended Posts

You can consider this method. Just keep in mind that before you assign this to a user you have to check for collision. Even if the chances are minuscule, there is always the possibility that you'll have generated this number previously.

 

 

<?php

// seed with microseconds
function make_seed()
{
  list($usec, $sec) = explode(' ', microtime());
  return (float) $sec + ((float) $usec * 100000);
}

mt_srand(make_seed());
for ($i=0; $i < 25; $i++) {
  $id = mt_rand() . '.' . mt_rand();
  echo $id . "\n";
}
You'll get this:

 

1430510990.211800510

1466558525.1174334161

505344300.1022366902

1102498041.512780900

2021435785.822065269

1067052107.2031154900

1573696108.839071663

1980123314.867137495

2084311793.1584365915

1003446906.1472857995

315507374.1484330943

142579337.206780113

1981674287.967067949

463749784.1337826872

332981579.604370553

815957892.954609975

1162600210.642213439

1685383521.1211289722

266829926.1463632230

59693777.670718427

1738677010.1526829074

1863209293.1713778803

1540998699.2715544

1268514048.212413847

1070525702.1303096993

Based on php's implementation of the Mersenne Twister algorithm.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.