Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8387869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:19:59+00:00 2026-06-09T18:19:59+00:00

I want to implement a saving system similar to Imgur where if a user

  • 0

I want to implement a saving system similar to Imgur where if a user presses a button a unique 5 character value is returned. Here is what I have so far:

The database backend uses auto-incrementing ID’s starting at 5308416. I use a modified Radix function (see below) to convert these numerical ID’s into characters. I use a reverse function to lookup character ID’s back to numerical database ID’s.

function genID (value)
{
    var alphabet = "23456789BCDFGHJKLMNPRSTVWXYZbcdfghjkmnpqrstvwxyz";

    var result = "";
    var length = alphabet.length;

    while (value > 0)
    {
        result = alphabet[value % length] + result;
        value  = Math.floor (value / length);
    }

    return result;
}

The problem is that these generated ID’s are very much predictable. My question is, how can I make the generated ID’s seem random but still unique (so I can look them up in the database as numbers). I was thinking of using some encryption algorithm but not sure where to start. Any help or suggestions would be appreciated (maybe there is a better way of doing this also).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:20:01+00:00Added an answer on June 9, 2026 at 6:20 pm

    Do you have to be able to go both ways (i.e. convert an integer to it’s hash and back again)? If you can store the hash and lookup the content that way, then it’s relatively easy to create a function that produces a hard-to-guess, but complete hash space. You use primes to generate a sequence that only repeats once all possible permutations are exhausted.

    The following PHP example is from my own code, adapted from this site:

    function hash($len = 6) {
        $base = 36;
        $gp = array(1,23,809,28837,1038073,37370257 /*,1345328833*/);
        $maxlen = count($gp);
        $len = $len > ($maxlen-1) ? ($maxlen-1) : $len;
        while($len < $maxlen && pow($base,$len) < $this->ID) $len++; 
        if($len >= $maxlen) throw new Exception($this->ID." out of range (max ".pow($base,$maxlen-1).")");
        $ceil = pow($base,$len);
        $prime = $gp[$len];
        $dechash = ($this->ID * $prime) % $ceil;
        $hash = base_convert($dechash, 10, $base);
        return str_pad($hash, $len, "0", STR_PAD_LEFT);
    }
    

    It would be easy enough to implement that in JavaScript, but ideally you wouldn’t need too – you’d have an insert trigger on your table that populated a hash field with the result of that algorithm (adapted for SQL, of course).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i starter in jqgrid, i want implement inline edit in jqgrid i have this
I want to implement an application which will work as a parser. User will
I'm trying to implement saving user's data in my application. I've created special method
I want to implement a two-pass cache system: The first pass generates a PHP
I want implement in my software solution an VBA editor but in c# 3.0.
given this class definition: public class Frame { IFrameStream CapturedFrom; } I want implement
Microsoft has announce that WindowsLiveID become a OpenID provider . I want implement it
I want to implement a simple script to do some boring housekeeping on my
I want to implement charting in SWT and I want to use GC.transform to
I want to implement a list of ViewPagers. Every item of a ListView is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.