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

  • Home
  • SEARCH
  • 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 387095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:38:24+00:00 2026-05-12T15:38:24+00:00

Suppose we have two longs, x and y. What operator or function involving x

  • 0

Suppose we have two longs, x and y. What operator or function involving x and y would produce another long, z, which is least likely to be equal to the result of applying the same operator or function to different of x’s and y’s?

Ex: Addition would be a poor choice. 1+4=5, but 2+3 also equals 5.

EDIT: Let me explain why I’m asking this question. I’m creating a space rpg game. The game’s environment (solarsystems) will be procedurally generated from two seeds. These seeds consist of the x and y coordinates of the system in the universe. So there is a good probability that the player might encounter the systems at (500,501) and (501,500) over the course of his adventures. I need a way to these the solar systems generated unique. But also, I want to make sure that as many coordinate pairs as possible will produce unique seeds.

EDIT 2: I tested two of the solutions given to me. Accipitridae’s answer was far superior to Artelius’s answer. Here’s the code to test the solutions:

HashSet<Long> set = new HashSet<Long>();

 for(int x=0; x<1000; x++)
  for(int y=0; y<1000; y++)
   //I commented out one of the solutions at a time
   set.add((long)(((x&0x7FFFFFFF) << 33) | ((y&0x7FFFFFFF) << 2) |   ((x>>>62) & 2) | (y>>>63)));//Artelius
   set.add((long)(x - y * 7046029254386353131l));//Accipitridae

 System.out.println(set.size());

From the size of the HashSet, I could tell how many unique seeds were generated through each method. For these parameters, Artelius’s solution generated 2048 unique longs, while Accipitridae’s generated 1000000, meaning that there were no collisions at all.

Thank you all for you effort in trying to solve this problem. 🙂

  • 1 1 Answer
  • 1 View
  • 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-12T15:38:25+00:00Added an answer on May 12, 2026 at 3:38 pm

    I like the answer and anlysis by Artelius. Especially the proposal to use

    f(x,y) = x + y*K

    for some constant K is interesting and I’d like to just add a few more thoughts.
    What I’m doing here is not new, but very closely related to the
    Fibonacci hashing, which I think has been proposed by Knuth.

    If we are using 64-bit integers then a collision f(x1, y1) = f(x2, y2) means

    0 = (dx + dy * K) mod 264,

    where dx = x1 – x2 and dy = y1 – y2. This is the same as

    K = -dx*dy-1 mod 264,

    where dy-1 is the modular inverse modulo 264. If we want to choose the K such that f(x1, y1) != f(x2, y2) whenever the differences dx and dy are both small then we have to choose K such that

    K = -dx*dy-1 mod 264,

    has no solution such that both dx and dy are small. This can be achieved for example by choosing
    K close to phi * 264, where phi = (sqrt(5)-1)/2 is the golden ratio. The golden ratio has a very special continued fraction expansion, i.e. in a certain sense it is a number that is hard to approximate well with a fraction.

    Hence, for 64-bit unsigned integers the following functions could be used

    f(x,y) = x + y * 11400714819323198485;

    or equivalently when using signed 64-bit integers

    f(x,y) = x – y * 7046029254386353131;

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

Sidebar

Related Questions

Suppose I have two applications written in C#. The first is a third party
Suppose you have two models, User and City, joined by a third model CityPermission:
Suppose I have two classes with the same interface: interface ISomeInterface { int foo{get;
Suppose you have two seperate ASP.NET Web Application projects that both need to use
Suppose I have two branches of a project IMClient-MacOS and IMClient-Windows, and their code
Suppose that you have two huge files (several GB) that you want to concatenate
Suppose I have the following two strings containing regular expressions. How do I coalesce
Suppose I have a database table with two fields, foo and bar. Neither of
Suppose I have a tags table with two columns: tagid and contentid . Each
Suppose I have a dataset with those two immortal tables: Employee & Order Emp

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.