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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:11:46+00:00 2026-06-12T08:11:46+00:00

I am interested in a function rand(x, y, seed) that returns (pseudo) random numbers

  • 0

I am interested in a function rand(x, y, seed) that returns (pseudo) random numbers based on its arguments, with the following properties:

  1. The value returned should depend on its 3 arguments, and not depend on the amount of times rand was called so far. For example, assuming these calls, in this order:

    rand(0, 0, 123) = 1
    rand(0, 1, 123) = 2
    rand(0, 2, 123) = 3
    

    Then calling rand with the same arguments, but in a different order, we should get the same values. For example:

    rand(0, 1, 123) = 2
    rand(0, 2, 123) = 3
    rand(0, 0, 123) = 1
    
  2. The function should have the usual properties of a good (decent, I don’t really need anything very fancy) PRNG: large period, uniform distribution etc. Returning positive integers that fit in a signed int is fine. It can also go higher if you want.

  3. Assume these numbers will be used to generate a matrix. Then changing the seed should ensure that the generated matrix looks as differently as possible from matrices generated by other seeds. This should happen for as large a number of seeds as possible: I don’t want matrices to repeat.

If it helps, my seeds will always be the unix timestamp in milliseconds (can be in seconds too if that makes it easier somehow). All arguments can go as high as 32 bit signed ints, but working with 64 bit values inside the function is not a problem.

What function could I use for this?

What I thought of:

Perlin noise seems to do some of what I want, but I have no idea how suitable it really is as a PRNG, especially distribution-wise. I’m also not sure how efficient it is, since my (x, y) parameters will be rather random, and I cannot precompute it for all of them.

I also looked into the following function:

p = 1400328593
rand(x, y, seed) = (x * x * seed + y * seed * seed + seed * x * y + seed) mod p
                 = (seed * (x * x + y * seed + x * y + 1)) mod p

This seems to generate good-enough numbers. Based on my (very weak) tests, they also seem to be distributed very well. Testing the period is harder though, I haven’t done that.

Update:

Here is the output of Ent for the above function, with time(NULL) in C as its seed and values generated for (x, y) in {0 ... 999} x {0 ... 999}:

Entropy = 3.312850 bits per byte.

Optimum compression would reduce the size of this 9207076 byte file by
58 percent.

Chi square distribution for 9207076 samples is 229710872.43, and
randomly would exceed this value less than 0.01 percent of the times.

Arithmetic mean value of data bytes is 52.3354 (127.5 = random). Monte
Carlo value for Pi is 4.000000000 (error 27.32 percent). Serial
correlation coefficient is 0.036131 (totally uncorrelated = 0.0).

Is this good enough in practice (in theory, the above tests suggest that it’s not good at all), or is there something well-known that I should be using?

  • 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-12T08:11:47+00:00Added an answer on June 12, 2026 at 8:11 am

    It sounds like you want a hash function. Pick a secure one such as SHA1 if it’s not too inefficient, since it’s guaranteed to have good distribution characteristics; otherwise, you can use a common hash function such as FNV. Simply use your seed and coordinates as the input data, and the hash as the random value.

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

Sidebar

Related Questions

I've a function, rev , that returns some value for a type that is
This question is based on the thread . I am interested in the function
I want to overload a function so that it manipulates its argument in some
I was interested to have the following getNumberOfDecimalPlace function: System.out.println(0 = + Utils.getNumberOfDecimalPlace(0)); //
I am interested in using a Listable Compiled function on lists that need not
I have an array of objects. I am interested in writing a function that
Say I have a Python function that returns multiple values in a tuple: def
I'll explain: Let's say I'm interested in replacing the rand() function used by a
I'm interested if there is any function like array_map or array_walk from php. Don't
I'm interested in calculation of Improper Integral for a function. Particularly it's a Gauss

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.