Last active
February 20, 2020 13:46
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function longid(id) { | |
return id > 0 ? (Math.pow(2, 32) * (Math.floor((Math.random() * 999) + 1))) + id : 0; | |
} | |
console.log(longid(19933)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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