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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:22:49+00:00 2026-05-19T17:22:49+00:00

As awesome an accidental feature as this is, it makes for a lousy way

  • 0

As awesome an accidental feature as this is, it makes for a lousy way to “shuffle” an array of “cards”. The fact that I’m getting the same number tells me I’ve having some problem in picking separate seeds each time. Am I using srand48 or the time(NULL) call improperly? Is there some underlying logic flaw I’m missing? Is there just not enough time inbetween iterations for the value of time() to be different?

The code is being run on Linux.

void shuffle()

{
  int i_rnd;   /* Integer random number, range 0..100 */
  int i_rnd2;
  card tempCard; /*temporary card to facillitate swapping*/
  int i = 0; /*can't use a FOR loop 'cause we're not using c99 standard*/
  while(i < 1000)
  {

      srand48( (unsigned) time( NULL ) );  /* Seed the random number generator */
      i_rnd = (int) ( drand48() * 100);
      i_rnd = i_rnd%52; // return a random number 0-51    
      i_rnd2 = (int) ( drand48() * 100);
      i_rnd2 = i_rnd2%52; // return a random number 0-51
      /*we have two random numbers, now exchange the two objects with the
      / picked array indices */
      tempCard =  cardDeck[i_rnd];
      cardDeck[i_rnd]=cardDeck[i_rnd2];
      cardDeck[i_rnd2]=tempCard;
      //swap complete. increment counter so we can eventually get out of the while
      i++;

  }

return;

}
  • 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-19T17:22:50+00:00Added an answer on May 19, 2026 at 5:22 pm

    You need to seed the pseudorandom number generator once, not every time you use it.

    Many (most?) pseudorandom number generators (PRNG) are deterministic given a certain seed value. If time() returns the same value each time your loop executes, you seed the PRNG with the same value just before you use it each time, so when you query it for random numbers it returns the same values.

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

Sidebar

Related Questions

I found this awesome plugin https://github.com/inuyaksa/jquery.nicescroll that turns the scrollbar into one that is
You awesome people may know how to do this. I know that once I
Windows 7 has an AWESOME new feature that applications can report the progress of
I just received this awesome help: Is there a way to extend background color
jQuery has this awesome simple way of disabling animations: jQuery.fx.off However, in practice, when
Clojure is awesome, we all know this, but that's not the point. I'm wondering
I had this awesome idea... but I am afraid maybe it is actually a
Attributes are awesome. But is it possible to create a C# attribute class that,
I'm writing this awesome application, at least I think it awesome, in C with
I got started by following this awesome tutorial , but wanted to do the

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.