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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:50:59+00:00 2026-06-02T03:50:59+00:00

This might be more Math related than C#, but I need a C# solution

  • 0

This might be more Math related than C#, but I need a C# solution so I’m putting it here.

My question is about the probability of random number generators, more specifically if each possible value is returned with an equal probability.

I know there is the Random.Next(int, int) method which returns a number between the first integer and last (with the last being exclusive).

Random.Next() [without overloads] will return a value between 0 and Int32.MaxValue (which is 2147483647) – 1, so 2147483646.

If I want a value between 1 and 10, I could call Random.Next(1, 11) to do this, however does every value between 1 and 10 have an equal probability of occuring?

For example, the range is 10, so 2147483646 is not perfectly divisible by 10, so the values 1-6 have a slightly higher probability of occuring (because 2147483646 % 10 = 6). This is of course assuming that every value within Random.Next() [without overloads] returns a value between 0 and 2147483646 with equal probability.

How would one ensure that every number within a range has an equal probability of occuring? Let’s say for a lottery type system where it would be unfair for some people to have a higher probility than others, I’m not saying I would use the C# built in RNG for this, I was just using it as an example.

  • 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-02T03:51:01+00:00Added an answer on June 2, 2026 at 3:51 am

    I note that no one actually answered the meaty question in your post:

    For example, the range is 10, so 2147483646 is not perfectly divisible by 10, so the values 1-6 have a slightly higher probability of occuring (because 2147483646 % 10 = 6). This is of course assuming that every value within Random.Next() [without overloads] returns a value between 0 and 2147483646 with equal probability.

    How would one ensure that every number within a range has an equal probability of occuring?

    Right, so you just throw out the values that cause the imbalance. For example, let’s say that you had a RNG that could produce a uniform distribution over { 0, 1, 2, 3, 4 }, and you wanted to use it to produce a uniform distribution over { 0, 1 }. The naive implementation is: draw from {0, 1, 2, 3, 4} and then return the value % 2; this, however, would obviously produce a biased sample. This happens because, as you note, 5 (the number of items) is not evenly divisible by 2. So, instead, throw any draws that produce the value 4. Thus, the algorithm would be

     draw from { 0, 1, 2, 3, 4 }
     if the value is 4, throw it out
     otherwise, return the value % 2
    

    You can use this basic idea to solve the general problem.

    however does every value between 1 and 10 have an equal probability of occuring?

    Yes, it does. From MSDN:

    Pseudo-random numbers are chosen with equal probability from a finite set of numbers.

    Edit: Apparently the documentation is NOT consistent with the current implementation in .NET. The documentation states the draws are uniform, but the code suggests that it is not. However, that does NOT negate the fact that this is a soluble problem, and my approach is one way to solve it.

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

Sidebar

Related Questions

OK. This might be more of a math question but here goes. I have
This might be more of a CYGWIN question than a Nodejs but here goes.
This might be more a geometry related question, but I'm trying to constrain a
The question might be related more to math than to programming. I'll explain the
This might be more of a philosophical debate, but here is what I have:
This might be more of a subjective question, but is it generally best practice
This is more of a challenge question than something I urgently need, so don't
This might be more of a philosophical question, but is there a compelling reason
This is a lot more complicated than it might seem at first. What I
This might be basic question but how do I create a list of lists

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.