Search code examples
rubyencryptioninvitation

Is there some ready-made algorithm to generate invitation code by ruby


Is there some ready-made algorithm to generate invitation code by ruby? I can think at first MD5, but its output is too long for 32, so I want the output length is less than 16.

Thank you in advance.


Solution

  • Assuming you are storing the code (otherwise, what's the point?) just make a random string, and check to see if it exists before saving, and try a new string if it does. No major algorithm needed.