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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:45:46+00:00 2026-05-21T07:45:46+00:00

I am new to c++ so this doubt might look basic but I am

  • 0

I am new to c++ so this doubt might look basic but I am not getting the difference between rand() and srand() and what do u mean by “seed” in srand()?
when I write srand(time(NULL)), what does it do to generate random numbers, what does time(NULL) do here? and what is it?
Thanks in advance

  • 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-21T07:45:47+00:00Added an answer on May 21, 2026 at 7:45 am

    A random number generator requires a number(it is called seed) to generate random numbers . If the random number generator is given the same seed then every time it will generate the same sequence of random numbers . For example :-

    If you run the program and it is generating random sequence 2,78,45,60 .
    If second time you run the program you will again get the same sequence 2,78,45,60.

    srand function is used to change the seed of the random number generator.By setting srand(time(NULL)) , you are setting the seed of the random number generator to the current time.By doing this every time you run the program you will get different random sequences :-

    For example for the first run if you are getting 2,78,45,60 .
    Next time you might get 5,3,6,80 (depending on the current time,as seed has been changed since the time has changed since the last run)

    for more info refer these :-

    http://www.cplusplus.com/reference/clibrary/cstdlib/rand/

    http://www.cplusplus.com/reference/clibrary/cstdlib/srand/

    http://www.cplusplus.com/reference/clibrary/ctime/time/

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

Sidebar

Related Questions

Why does this: (new[]{1,2,3}).Cast<decimal>(); result in an InvalidCastException: Specified cast is not valid.
I'm new to this SCM, but since SVN is gaining popularity I was going
I'm very new at this, but I need to create new tables from existing
I doubt this is possible, but I was curious if you could have more
I doubt this is possible but what I would like to do is have
This question has been asked again and again, but I have still a doubt.
I am very new to software development, so this is no doubt a very
This might be simple for seasoned java developers but I just cant seem to
I am new this sharepoint development and i have task in hand to do
New to this library (no more familiar with BeautifulSoup either, sadly), trying to do

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.