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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:00:00+00:00 2026-06-12T20:00:00+00:00

If num parameter is 52, how many possible return values are there? is it

  • 0

If num parameter is 52, how many possible return values are there? is it 52 or 53? If I understand this correctly, Math.random uses random values from 0 to 1 inclusive. If so, then 0 is a possible return value and so is 52. This results in 53 possible return values. Is this correct? Reason I ask is that a book that I’m learning from uses this code for a deck of cards. I wonder if num should equal 51 ?

Thanks …

function getRandom(num) {
    var my_num = Math.floor(Math.random * num);
    return my_num;
};
  • 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-12T20:00:02+00:00Added an answer on June 12, 2026 at 8:00 pm
    Math.floor(Math.random() * num) // note random() is a function.
    

    This will return all integers from 0 (including 0) to num (NOT including num).

    Math.random returns a number between 0 (inclusive) and 1 (exclusive). Multiplying the result by X gives you between 0 (inclusive) and X (exclusive). Adding or subtracting X shifts the range by +-X.

    Here’s some handy functions from MDN:

    // Returns a random number between 0 (inclusive) and 1 (exclusive)
    function getRandom() {
      return Math.random();
    }
    
    // Returns a random number between min and max
    function getRandomArbitrary(min, max) {
      return Math.random() * (max - min) + min;
    }
    
    // Returns a random integer between min and max
    // Using Math.round() will give you a non-uniform distribution!
    function getRandomInt(min, max) {
      return Math.floor(Math.random() * (max - min + 1)) + min;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There have been many threads started over the confusion in the way that Math.Round
Possible Duplicate: mysql_fetch_array() expects parameter 1 to be resource, boolean given in select I
I am working with a Class that contains constants or parameter values that all
I get this error whenever I run this: Warning: mysql_num_rows() expects parameter 1 to
public function doesUserExist($u) { $this->dbConnect(); mysql_select_db($this->database); $sUser = mysql_real_escape_string($u); $query = SELECT username FROM
How do you understand the class parameter in scala. Will the compiler add implicit
I got this linq example from msdns 101 linq examples: public void Linq12() {
I have stocked in this error many times but know I have no way
$result=mysql_query(SELECT * FROM users WHERE pass='.sha1($_POST['mainloginpass']).'); if(mysql_num_rows($result)==1){ it says that mysql_num_rows() expects parameter 1
Possible Duplicate: PHP Error: mysql_fetch_array() expects parameter 1 to be resource, boolean given I

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.