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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:01:08+00:00 2026-05-13T14:01:08+00:00

Javascript’s MATH object has a random method that returns from the set [0,1) 0

  • 0

Javascript’s MATH object has a random method that returns from the set [0,1) 0 inclusive, 1 exclusive. Is there a way to return a truly random method that includes 1.

e.g.

var rand = MATH.random()*2;

if(rand > 1)
{
   rand = MATH.floor(rand);
}

return rand; 

While this always returns a number from the set [0,1] it is not truly random.

  • 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-13T14:01:08+00:00Added an answer on May 13, 2026 at 2:01 pm

    To put it bluntly, what you’re trying to do doesn’t make sense.

    Remember that under a continuous probability distribution, the probability of getting a specific value is infinitesimal, so mathematically speaking you will never see the exact value of 1.

    Of course, in the world of computers, the distribution of an RNG isn’t truly continuous, so it’s "possible" that you’ll encounter a specific value (as silly as that sounds), but the probability will be so vanishingly small that in practice you will never observe it.

    To make the point a bit more clearly: if you did manage to write such a function in terms of double-precision floats, the probability of getting exactly 1 would be approximately 2-64. If you called the function 1 million times per second, you would have to wait around 600,000 years before you got a 1.

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

Sidebar

Related Questions

JavaScript has lexical scoping which means that non-local variables accessed from within a function
Javascript's getTime() method returns the number of milliseconds since midnight of January 1, 1970.
JavaScript object created with a prototype maintains live connection to its prototype, so that
Javascript has textObject.defaultValue=somevalue for retrieving the default value (stored value from page load) of
JavaScript has two handy substring functions: substring(from,to) and substr(start,length) . This means I can
Javascript I have code that will hide various sections in a MS CRM form
javascript with> var customer=document.getElementById('custList').value; and that works... Why does it work BUT... var customer=(form1.custList.value);
Javascript setTimeOut fires any way when i load new section with ajax. I wrote
JavaScript is known to be single-threaded in all modern browser implementations, but is that
Javascript functions can be declared on a objects prototype like this: <object name>.prototype.<variable name>=function(){

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.