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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:25:29+00:00 2026-05-25T02:25:29+00:00

I need to generate a deterministic (i.e. repeatable) sequence of pseudo-random numbers given an

  • 0

I need to generate a deterministic (i.e. repeatable) sequence of pseudo-random numbers given an initial seed and select the nth item from that sequence.

If JavaScript’s random function was seedable, I could just do:

function randomNth(seed, seq)
{
    var r;
    Math.randomSeed(seed);
    for (var i = 0; i++ < seq; i++)
    {
        r = Math.random();
    }
    return r;
}

However, it’s not, and alternative, seedable PRNGs look to be a little slow; asking for the 250th number would be expensive.

I think a hash is what I want here, perhaps something like md5(seed + seq) % max but JavaScript doesn’t have md5() and if I’m doing it in code there’s probably a better choice of hash.

I’d like a function where

x = randomNth(seed, seq, maxVal) // x is int && x >= 0 && x < maxVal

or, ideally

x = randomNth(seed, seq) // x >= 0 && x < 1, same as Math.random()

Other requirements:

  • must run in node.js and in a browser
  • numbers should be statistically random (or close enough as the period will be small)
  • should be O(1) and reasonably performant
  • 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-25T02:25:30+00:00Added an answer on May 25, 2026 at 2:25 am

    There are some good int -> int hashing functions on this page you can use one of them.

    function hash(a)
    {
        a = (a+0x7ed55d16) + (a<<12);
        a = (a^0xc761c23c) ^ (a>>19);
        a = (a+0x165667b1) + (a<<5);
        a = (a+0xd3a2646c) ^ (a<<9);
        a = (a+0xfd7046c5) + (a<<3);
        a = (a^0xb55a4f09) ^ (a>>16);
        if( a < 0 ) a = 0xffffffff + a;
        return a;
    }
    var seed = 26254;
    var index = 250;
    alert( hash( seed + index ) );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to generate a random integer between 1 and n (where n is
I need to generate thumbnails from a set of jpg's that need to have
I need to generate multiple random values under SQL Server 2005 and somehow this
I need to generate a resource domain prefix based on a given path and
I need to be able to generate a single random number and then use
I need to generate unique 64 bits integers from Python. I've checked out the
i need to generate random character in a String java when user click on
I need to generate a lot of random 2 character strings for my application.
I need to generate a unique code from a single PC, my software will
I need generate thumbnails for a bunch of jpegs (200,000+) but I want 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.