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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:55:26+00:00 2026-05-26T01:55:26+00:00

I needed a function to generate a pseudo-random integer between m and n, and

  • 0

I needed a function to generate a pseudo-random integer between m and n, and so I thought, “I know, I’ll extend Math with a randrange method, similar to Python’s”.

Math.constructor.prototype.rand = function rand(min, max) {
    return min + Math.floor(Math.random() * (max + 1 - min));
};

This seems to work, but when I put it into my integrated code, I experienced multiple problems with error messages like “[that function] has no method ‘addEventListener'”.

The gist of my question is this: Is there something fundamentally wrong with the way I’ve extended Math here? Should that function have such a method, and if not, why is jwplayer asking for it?

I’ve attached much more detail below, but if you’re already bored and want to start postulating answers, you can skip the rest.


When I went to test the integrated code I saw this error:

jwplayer.js:1 Uncaught TypeError: Object function rand(min, max) {
        return min + Math.floor(Math.random() * (max + 1 - min));
    } has no method 'addEventListener'
jwplayer.js:1 a.plugins.pluginloader.load
jwplayer.js:1 a.embed
jwplayer.js:1 b.api.setup
script.js:155 (anonymous function)
jquery-1.6.4.js:660 jQuery.extend.each
jquery-1.6.4.js:274 jQuery.fn.jQuery.each
script.js:150 jQuery.click.window.Modernizr.input.required
jquery-1.6.4.js:1016 jQuery.extend._Deferred.deferred.resolveWith
jquery-1.6.4.js:437 jQuery.extend.ready
jquery-1.6.4.js:923 DOMContentLoaded

Here’s a snippet from script.js that the above refers to:

// Setup the video player:
$("video").each(function (i, e) {
    // Switching out ids like this is a horrible hack,
    // but apparently it's the only way jwplayer will load.
    var oldId = $(e).attr('id');
    $(e).attr("id", "tmpVideoSetup");
    jwplayer("tmpVideoSetup").setup({
        flashplayer: window.CDN + "/js/libs/mediaplayer-5.7-licensed/player.swf",
        levels: [
            // TODO: set this up to dynamically choose the videos to play.
            { file: window.CDN + "/videos/LK_About.mp4" },
            { file: window.CDN + "/videos/LK_About.wmv" }
        ]
    });
    $(e).attr("id", oldId);
});

When I remove the video-loading code, everything else behaves as expected.

  • 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-26T01:55:26+00:00Added an answer on May 26, 2026 at 1:55 am

    Why attach it to Math at all? And if you’re going to, what’s wrong with Math.rand = ...?

    The Math Object isn’t supposed to be extended in a prototypal manner, because it’s a “static” type. You cannot instantiate it (i.e. call it with new). This is an exceptional case. All other types are “non-static”. Although that shouldn’t be surprising, Math is simply a collection of static methods. There is no need for any instantiation.

    Math.constructor === Object (at least in chrome), so you’re actually extending every object’s prototype, and presumably the other library is enumerating over all object properties. For example:

    Math.constructor.prototype.prop = 42;
    k = {};
    k.prop; // 42
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I working with jQuery and i needed to generate an anonymous method with the
I needed a function that simply checks if a string can be converted to
I have read about dynamically loading your class files when needed in a function
Help needed. Im writing a function that returns result of ajax call but i
I was just working on a function that I needed to return two values,
I have the following need (in python): generate all possible tuples of length 12
What is the difference between a multi-collision in a hash function and a first
Is there a way to know and output the stack size needed by a
I've seen the many different ways I can build a function/service to generate short
I have a function that generates a random combination. my function looks like this:

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.