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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:22:51+00:00 2026-06-10T16:22:51+00:00

I am looking to implement a simple pseudorandom number generator (PRNG) that has a

  • 0

I am looking to implement a simple pseudorandom number generator (PRNG) that has a specified period and guaranteed no collisions for the duration of that period. After doing some research I came across the very famous LCG which is perfect. The problem is, I am having trouble understanding how to properly configure it. Here is my current implementation:

    function LCG (state)
    {
        var a = ?;
        var c = ?;
        var m = ?;

        return (a * state + c) % m;
    }

It says that in order to have a full period for all seed values the following conditions must be met:

  1. c and m are relatively prime
  2. a-1 is divisible by all prime factors of m
  3. a-1 is a multiple of 4 if m is a multiple of 4

1 and 3 are simple to understand and test for. However what about 2, I don’t quite understand what that means or how to check for it. And what about C, can it be zero? what if it’s non-zero?

Overall I need to select A, C and M in such a way that I have a period of 48^5 – 1. M is equal to the period, I am not sure about A and C.

  • 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-10T16:22:53+00:00Added an answer on June 10, 2026 at 4:22 pm

    From Wikipedia:

    Provided that c is nonzero, the LCG will have a full period for all seed values if and only if:

    1. c and m are relatively prime,
    2. a-1 is divisible by all prime factors of m,
    3. a-1 is a multiple of 4 if m is a multiple of 4.

    You said you want a period of 485-1, so you must choose m≥485-1. Let’s try choosing m=485-1 and see where that takes us. The conditions from the Wikipedia article prohibit you from choosing c=0 if you want the period to be m.

    Note that 11, 47, 541, and 911 are the prime factors of 485-1, since they’re all prime and 11*47*541*911 = 485-1.

    Let’s go through each of those conditions:

    1. For c and m to be relatively prime, c and m must have no common prime factors. So, pick any prime numbers other than 11, 47, 541, and 911, then multiply them together to choose your c.
    2. You’ll need to choose a such that a-1 is divisible by all the prime factors of m, i.e., a = x*11*47*541*911 + 1 for any x of your choosing.
    3. Your m is not a multiple of 4, so you can ignore the third condition.

    In summary:

    • m = 485-1,
    • c = any product of primes other than 11, 47, 541, and 911 (also, c must be less than m),
    • a = x*11*47*541*911 + 1, for any nonnegative x of your choice (also, a must be less than m).

    Here’s a smaller test case (in Python) using a period of 482-1 (which has prime factors 7 and 47):

    def lcg(state):
        x = 1
        a = x*7*47 + 1
        c = 100
        m = 48**2 - 1
        return (a * state + c) % m
    
    expected_period = 48**2 - 1
    seeds = [5]
    for i in range(expected_period):
        seeds.append(lcg(seeds[-1]))
    print(len(set(seeds)) == expected_period)
    

    It outputs True, as it should. (If you have any trouble reading Python, let me know and I can translate it to JavaScript.)

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

Sidebar

Related Questions

Im looking to implement an application that is working with and displaying simple graph.
I'm looking to implement the jQuery UI so that the slider bar fills one
I'm looking to implement a simple cache without doing too much work (naturally). It
I've used the State pattern to implement a simple finite state machine. Looking at
I'm looking to implement a simple timer mechanism in C++. The code should work
I am looking for a simple way to implement simple coming soon (pre-launch) page
I'm looking for a very simple-to-implement horizontal accordion and was wondering what others are
I am looking to implement a simple forward indexer in PHP. Yes I do
I am looking to implement a simple search function while using the globalize3 gem
I'm looking to implement a very simple Paypal integration whereby I can enter a

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.