Skip to content

Instantly share code, notes, and snippets.

@hypertensy
Last active February 20, 2020 13:46
Show Gist options
  • Save hypertensy/0748bd0d03e80c19335ad97aa918cc05 to your computer and use it in GitHub Desktop.
Save hypertensy/0748bd0d03e80c19335ad97aa918cc05 to your computer and use it in GitHub Desktop.
Generating a long VK user IDs, or a banal overflow of a 32-bit integer

Below are examples of generating random long identifiers in different programming languages

function longid(id) {
return id > 0 ? (Math.pow(2, 32) * (Math.floor((Math.random() * 999) + 1))) + id : 0;
}
console.log(longid(19933));
<?php
function longid($id): int {
return $id > 0 ? ((2 ** 32) * rand(1, 999)) + $id : 0;
}
echo longid(19933);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment