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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:40:21+00:00 2026-05-20T21:40:21+00:00

I want to create an array of random/pseudo-random numbers using a seed. I want

  • 0

I want to create an array of random/pseudo-random numbers using a seed. I want the very same array to be created when the same seed is used and I want to have little or no visible pattern in the array. I’m working in JavaScript.

This is the random function I’m using, which I’m quite happy with (sorry, I forgot who the original author is):

function random(seed) {
    if (!seed) seed = new Date().getTime();
    seed = (seed*9301+49297) % 233280;
    return seed/(233280.0);
}

This is the array generation:

var superSeed = random();
var nRandom = 100;
var randomArray = new Array();
for (var i = 0 ; i < nRandom ; i++){
    randomArray.push(random((superSeed*10)+ (i)));
}

Somehow the pattern seems to be quite similar, no matter how often I run it. This question seems to be similar, but since it’s about matrixes, I don’t understand what’s being said.

Thanks!

  • 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-20T21:40:22+00:00Added an answer on May 20, 2026 at 9:40 pm

    Having worked on similar things before I think we can use a fairly simple series, which takes two initial values and then you can get a lot more.

    var a1,b1;
    
    function InitSequence(v1, v2) {
        a1 = Math.pow(v1, 5) / Math.pow(v1, 3);
        b1 = Math.pow(v2, 8);
        lastrand = (a1 + b1) & 0x7fffffff;
    }
    
    function SequenceNext() {
        var alast = a1;
        var nextVal = (a1 + b1) & 0x7fffffff;
        b1 = alast;
        a1 = nextVal;
        return nextVal;
    }
    

    Then use it like this:

    InitSequence(75, 21);
    for (var i = 0; i < 99; i++) {
        v = SequenceNext();
    }
    

    I tested it like this:

    var used = new Array();
    
    InitSequence(75, 21); // any two values will do.
    
    // fill 10k into array.
    
    for (var i = 0; i < 9999; i++) {
        v = SequenceNext();
        if (undefined != used[v]) {
            used[v]++;
        } else used[v] = 1;
    
        //document.write(i+": "+v+"<br>");
    }
    
    // see if there any duplicates.
    var tdup = 0;
    for (xx in used) {
        ndup = used[xx];
        if (ndup > 1) {
            document.write("duplicated " + xx + " :" + ndup + "<br>");
            tdup += ndup;
        }
    }
    document.write("Total dups " + tdup + "<br>");
    

    This is using the Fibonacci series, which in mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation
    Fibonacci  recurrence relation. I’m starting with different values – (v1^5) / (v1^3) and v2 ^ 8; otherwise it would only ever be identical.

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

Sidebar

Related Questions

I want to create a dynamic 2d array by function but it seems that
I want to create an array, populating it while reading elements from a .txt
I would want to create an array that will hold records retrieved from a
Hey! I want to create an array of fields. however my code return an
I have a custom class, class Result end and i want to create an
I know that to create array with integers in Object-c they have to be
I have a table mapping strings to numbers like this: t['a']=10 t['b']=2 t['c']=4 t['d']=11
I have a generic class defined like this class MyGenericClass<T> where T : ICompareable
I'm trying to use the Simple hill climbing algorithm to solve the travelling salesman
class MyGenericClass<T> where T : ICompareable { T[] data; public AddData(T[] values) { data

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.