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 844947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:22:03+00:00 2026-05-15T06:22:03+00:00

I would like an algorithm for a function that takes n integers and returns

  • 0

I would like an algorithm for a function that takes n integers and returns one integer. For small changes in the input, the resulting integer should vary greatly. Even though I’ve taken a number of courses in math, I have not used that knowledge very much and now I need some help…

An important property of this function should be that if it is used with coordinate pairs as input and the result is plotted (as a grayscale value for example) on an image, any repeating patterns should only be visible if the image is very big.

I have experimented with various algorithms for pseudo-random numbers with little success and finally it struck me that md5 almost meets my criteria, except that it is not for numbers (at least not from what I know). That resulted in something like this Python prototype (for n = 2, it could easily be changed to take a list of integers of course):

import hashlib
def uniqnum(x, y):
    return int(hashlib.md5(str(x) + ',' + str(y)).hexdigest()[-6:], 16)

But obviously it feels wrong to go over strings when both input and output are integers. What would be a good replacement for this implementation (in pseudo-code, python, or whatever language)?

  • 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-05-15T06:22:04+00:00Added an answer on May 15, 2026 at 6:22 am

    A “hash” is the solution created to solve exactly the problem you are describing. See wikipedia’s article

    Any hash function you use will be nice; hash functions tend to be judged based on these criteria:

    • The degree to which they prevent collisions (two separate inputs producing the same output) — a by-product of this is the degree to which the function minimizes outputs that may never be reached from any input.
    • The uniformity the distribution of its outputs given a uniformly distributed set of inputs
    • The degree to which small changes in the input create large changes in the output.

    (see perfect hash function)

    Given how hard it is to create a hash function that maximizes all of these criteria, why not just use one of the most commonly used and relied-on existing hash functions there already are?

    From what it seems, turning integers into strings almost seems like another layer of encryption! (which is good for your purposes, I’d assume)

    However, your question asks for hash functions that deal specifically with numbers, so here we go.


    Hash functions that work over the integers

    If you want to borrow already-existing algorithms, you may want to dabble in pseudo-random number generators

    One simple one is the middle square method:

    • Take a digit number
    • Square it
    • Chop off the digits and leave the middle digits with the same length as your original.

    ie,

    1111 => 01234321 => 2342
    

    so, 1111 would be “hashed” to 2342, in the middle square method.

    This way isn’t that effective, but for a few number of hashes, this has very low collision rates, a uniform distribution, and great chaos-potential (small changes => big changes). But if you have many values, time to look for something else…

    The grand-daddy of all feasibly efficient and simple random number generators is the (Mersenne Twister)[http://en.wikipedia.org/wiki/Mersenne_twister%5D. In fact, an implementation is probably out there for every programming language imaginable. Your hash “input” is something that will be called a “seed” in their terminology.

    In conclusion

    1. Nothing wrong with string-based hash functions
    2. If you want to stick with the integers and be fancy, try using your number as a seed for a pseudo-random number generator.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating an algorithm that is based on directed graphs. I would like
Suppose a general sliding algorithm that executes some function on a kernel, like a
I would like to find a better algorithm to solve the following problem: There
I would like to know if there's an efficient algorithm to find the greatest
I would like to know if there exist algorithms that solves this issue. It
I would like to write a dictionary. What algorithms/structures should I use? Each word
Would like a for loop in jquery so that: For every hover_link: show hidden
I have this Python code that I found online and would like to know
I wrote a quicksort algorithm however, I would like to make a change somewhere
I'd like an efficient algorithm (or library) that I can use in Java to

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.