Search code examples
phprandomgroupingdivide

Divide randomly generated ids into equal groups


i'm using php and generating user's id like

 $id = bin2hex(openssl_random_pseudo_bytes(16, $s));

And i would like to divide these ids into equals (or almost equals) groups. And in future i would like to know which group user belongs to.

Any ideas? What criteria can i choose for this?


Solution

  • I've found one variant of resolution. But maybe there is another, more pretty way...

    $group = array_sum(str_split($id))%2;