Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Add an offset, multiply by a large prime number, and modulo. I don't think you can recover the original number without figuring out the prime.


Ah, that's neat. Why is the offset necessary?


Might not be, but I like to start with a big number instead of 0 or 1 to fill all the bits. For example, if your prime is 100019, then your first number in binary is 00011000011010110011 but if your max number is something like 2^53 (00100000000000000000000000000000000000000000000000000000) then you have a lot of unfilled bits. The way I have mine set up, the output ID is always exactly 9 chars. 99% of the time it's naturally 9 chars because just by probability most of the numbers will be large, but some of them come out 8 chars and then I just pad up to 9 so it's nice and consistent.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: