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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:45:54+00:00 2026-06-12T03:45:54+00:00

Possible Duplicate: How does rand() work? Does it have certain tendencies? Is there something

  • 0

Possible Duplicate:
How does rand() work? Does it have certain tendencies? Is there something better to use?

I know how to implement it. However, I would like to understand how the rand behaves internally and why is it necessary to initialise a ‘seed’ value for the rand function.

Alternately put — how does the rand function use the seed value to generate random numbers?

  • 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-12T03:45:57+00:00Added an answer on June 12, 2026 at 3:45 am

    The exact implementation details are up to the implementors. But the GNU implementation (glibc) implements rand() like that:
    http://sourceware.org/git/?p=glibc.git;a=blob;f=stdlib/random_r.c;hb=glibc-2.15#l361

    The comment explains it pretty well.

    /* If we are using the trivial TYPE_0 R.N.G., just do the old linear
        congruential bit.  Otherwise, we do our fancy trinomial stuff,
        which is the same in all the other cases due to all the global
        variables that have been set up.  The basic operation is to add
        the number at the rear pointer into the one at the front
        pointer.  Then both pointers are advanced to the next location
        cyclically in the table.  The value returned is the sum generated, 
        reduced to 31 bits by throwing away the "least random" low bit.    
        Note: The code takes advantage of the fact that both the front and 
        rear pointers can't wrap on the same call by not testing the rear  
        pointer if the front one has wrapped.  Returns a 31-bit random number. */
    

    Regarding your question why you always need a seed value: There are no truly random numbers in computer science. Computers are (in computation theory) completely deterministic machines. They can’t perform any operations with an outcome which is up to chance.

    There are only pseudorandom number generators which generate streams of numbers which look random, but they are still the results of deterministic calculations. That’s why you need a seed value: each seed results in a different sequence of numbers. When you use the same seed, you get the same sequence of pseudorandom numbers.

    The behavior that a RNG always returns the same sequence when getting the same seed can be exploited: The classic space simulation Elite, for example, was able to store a huge universe with hundreds of planets in a single integer. How did it do that? The whole universe was randomly-generated. All data which was required to recreate the universe was the seed value, which always resulted in the exact same universe being generated.

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

Sidebar

Related Questions

Possible Duplicate: How does rand() work? Does it have certain tendencies? Is there something
Possible Duplicate: Does a exception with just a raise have any use? Is there
Possible Duplicate: Does there exist a static_warning? I often use #warning scattered through my
Possible Duplicate: Does JavaScript have a range() equivalent? Is there a way to declare
Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
Possible Duplicate: Does there exist a static_warning? Is there a way to implement non
Possible Duplicate: Does anyone know of a good C# API for Subversion? I'm designing
Possible Duplicate: How does this CSS triangle shape work? Please help me i need
Possible Duplicate: Why does the background of TextView change it's size? I have a
Possible Duplicate: Does Java guarantee that Object.getClass() == Object.getClass()? If I have a class

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.