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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:31:29+00:00 2026-05-11T15:31:29+00:00

Update : Please file this under bad ideas. You don’t get anything for free

  • 0

Update: Please file this under bad ideas. You don’t get anything for free in life and here is certainly proof. A simple idea gone bad. It is definitely something to learn from however.

Lazy programming challenge. If I pass a function that 50-50 returns true or false for the qsort’s comparision function I think that I can effectively unsort an array of structures writing 3 lines of code.

int main ( int argc, char **argv) {     srand( time(NULL) );  /* 1 */     ...     /* qsort(....) */     /* 2 */ } 

…

int comp_nums(const int *num1, const int *num2) {     float frand =            (float) (rand()) / ((float) (RAND_MAX+1.0));  /* 3 */      if (frand >= 0.5f)          return GREATER_THAN;     return LESS_THAN; } 

Any pitfalls I need to look for? Is it possible in fewer lines through swapping or is this the cleanest I get for 3 non trivial lines?

  • 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. 2026-05-11T15:31:30+00:00Added an answer on May 11, 2026 at 3:31 pm

    Bad idea. I mean really bad.

    Your solution gives an unpredictable result, not a random result and there is a big difference. You have no real idea of what a qsort with a random comparison will do and whether all combinations are equally likely. This is the most important criterion for a shuffle: all combinations must be equally likely. Biased results equal big trouble. There’s no way to prove that in your example.

    You should implement the Fisher-Yates shuffle (otherwise known as the Knuth shuffle).

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

Sidebar

Related Questions

Please help me with this update query. I COMPLETELY understand how redundant this is
MySQL CMD Client will run this file but get half way through and complain
(Please see update at bottom) I've looked at dozens of questions and haven't been
Please read my update at the end of question after reading the answers: I'm
I need to update jquery1.3.2 to jquery1.4 (in Asp.net MVC). Please can anyone tell
How do we update a textbox on ticking checkboxes? Please see the following code,
Update: I reported this as a bug to Apple and they fixed it! All
UPDATE: I've been playing around with this more, and it seems like tmux's clear-history
According to this MSDN article about medium trust , under medium-trust: FileIOPermission is restricted.
Edit: 2020 update -- Please disregard the question below as Google's weather API is

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.