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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.