Coder Social home page Coder Social logo

Comments (4)

manigandham avatar manigandham commented on May 31, 2024 1

I haven't looked at the algorithm in a while but you can check it here: https://hashids.org/

Different salts with the same integer input will have different outputs. Different salts with any arbitrary input will have duplicate outputs at some point as far as I know, and you can test this by decoding encoded hashes with different salts. This should be rare though.

If you already have your categories set then you can do a quick test by generating a 100k values for each and see if any duplicates show up. If you have enough unique IDs to work with then you might not have to worry about it.

from hashids.net.

ullmark avatar ullmark commented on May 31, 2024 1

I am not sure either tbh, but I would guess that the outputs can contain duplicate values in that scenario.

But why not just let salt remain the same and pass in the category as the first value and the "id" be the second. [1, 4] to generate a short id?

from hashids.net.

ckpearson avatar ckpearson commented on May 31, 2024

Thanks for the reply both, will take a look at generating a large number of IDs to check for clashes.

Our category is a string value so not sure we could use it as an additional encode value.

If we start running into clashes we can always prefix the generated hashID with something to scope them.

Appreciate we're using it for ID generation rather than ID obfuscation 👍

from hashids.net.

ullmark avatar ullmark commented on May 31, 2024

@ckpearson Ok, I'm obviously not informed into your details enough to really know, but from sound of it, you're trying to use Hashids for a task that it might not be best suited for... but with that said;

I would still recommend you to have an integer id stored together with your data that you can use hashids with to encode. That's what the library is for, not generating id:s.

from hashids.net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.