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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:03:19+00:00 2026-05-25T14:03:19+00:00

Why if I use random number generator and range 0 – 9 I don’t

  • 0

Why if I use random number generator and range 0 – 9 I don’t get the same uniform distribution as combined it with the floor function?

  • 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-25T14:03:20+00:00Added an answer on May 25, 2026 at 2:03 pm

    Math.floor(Math.random() * 10) gives quite uniform distribution, while Math.round(Math.random() * 10) doesn’t.

    Math.floor() returns 0 for any value in the range [0, 1) (1 exclusive), 1 for any value in the range [1, 2), etc.

    So if we have equal chances of getting a number in one of these ranges, we will get an equal distribution of 0’s and 1’s.

    Math.round(), however, returns 0 for values under 0.5, 1 for values under 1.5, etc.

    So we actually have half the chances of getting a 0, as only values from 0 to 0.5 will round to 0.

    ╔═════════╦═════════╦═════════╗
    ║  Range  ║ floor() ║ round() ║
    ╠═════════╬═════════╬═════════╣
    ║ [0, 1)  ║ 0       ║ 0 or 1  ║
    ║ [1, 2)  ║ 1       ║ 1 or 2  ║
    ║ [2, 3)  ║ 2       ║ 2 or 3  ║
    ║ ...     ║ ...     ║ ...     ║
    ║ [9, 10) ║ 9       ║ 9 or 10 ║
    ╚═════════╩═════════╩═════════╝
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I use the same random number generator in my Python with numpy
I need help on which random number generator to use simultaneously from multiple threads
When using a Random Number Generator, which is the better way to use it
I need to perform few tests where I use randn pseudo random number generator.
I want to use a random number generator that creates random numbers in a
Why would anybody use the standard random number generator from System.Random at all instead
If I want to use the gaussian random number generator in MATLAB R =
I was trying to use a random number generator in a windows forms app,
I use this code to generate a random number. Random R = new Random(0);
Possible Duplicate: How to generate a random number from within a range - C

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.