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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:14:37+00:00 2026-05-25T17:14:37+00:00

As far as I know rand() does not generate a uniform random distribution. What

  • 0

As far as I know rand() does not generate a uniform random distribution. What function/algorithm will allow me to do so? I have no need for cryptographic randomness, only a uniform random distribution. Lastly, what libraries provide these functions?
Thanks!

  • 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-25T17:14:37+00:00Added an answer on May 25, 2026 at 5:14 pm

    rand() does generate a uniform (pseudo-)random distribution.

    The actual requirement, from the C standard (3.7 MB PDF), section 7.20.2.1, is:

    The rand function computes a sequence of pseudo-random integers in
    the range 0 to RAND_MAX.

    where RAND_MAX is at least 32767. That’s admittedly vague, but the intent is that it gives you a uniform distribution — and in practice, that’s what implementations actually do.

    The standard provides a sample implementation, but C implementations aren’t required to use it.

    In practice, there are certainly better random number generators out there. And one specific requirement for rand() is that it must produce exactly the same sequence of numbers for a given seed (argument to srand()). Your description doesn’t indicate that that would be a problem for you.

    One problem is that rand() gives you uniformly distributed numbers in a fixed range. If you want numbers in a different range, you have to do some extra work. For example, if RAND_MAX is 32767, then rand() can produce 32768 distinct values; you can’t get random numbers in the range 0..9 without discarding some values, since there’s no way to evenly distribute those 32768 distinct values into 10 equal sized buckets.

    Other PRNGs are likely to give you better results than rand(), but they’re still probably going to be subject to the same issues.

    As usual, the comp.lang.c FAQ answers this better than I did; see questions 13.15 through 13.21.

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

Sidebar

Related Questions

Python, as far as know, does not allow modification of an archived file. That
I know that I can generate random floats with rand(max). I tried to generate
As far as i know it is not possible to do the following in
As far as I know (not much I'll admit), the currently popular programming paradigms
As far I know this is not supported for asp.net projects. It's quite handy
I have searched high, low, far and wide but can not find anything on
I need to do something like: This is how far I know: http://jsbin.com/apikiw/3/edit#preview The
I have encountered the following problem which proved to me that I know far
As far as know, I must be careful with PHP, and I think Javascript.
As far as I know, foreign keys (FK) are used to aid the programmer

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.