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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:43:10+00:00 2026-05-16T04:43:10+00:00

I am just trying to implement a simple RNG in JS. What’s happening is

  • 0

I am just trying to implement a simple RNG in JS.

What’s happening is javascript evaluates 119106029 * 1103515245 to be 131435318772912110 rather than 131435318772912105. We know it’s wrong since two odd numbers multiplied does not give an even number.

Anyone know what’s up? I just want a reliable repeatable RNG, and because of these incorrect values I can’t get results to match up with my C implementation of the same thing.

  • 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-16T04:43:11+00:00Added an answer on May 16, 2026 at 4:43 am

    Per the ECMAScript standard, all numbers in JavaScript are (64-bit IEEE 754) floating-point numbers by default.

    However all 32-bit integers can be exactly represented as floating-point numbers. You can force a result to 32 bits by using the appropriate bitwise operator, like this:

    x = (a * b) >>> 0;  // force to unsigned int32
    x = (a * b) | 0;    // force to signed int32
    

    Weird, but that’s the standard.

    (Incidentally this rounding behavior is one of the most frequently reported "bugs" against Firefox’s JavaScript engine. Looks like it’s been reported 3 times so far this year…)

    If you want real integer math, you can use BigInt values, a different type of number, written with an n at the end:

    > 119106029n * 1103515245n
    131435318772912105n
    

    This is a relatively recent JS feature, and may not be implemented in old browsers.


    As for reproducible random numbers in JavaScript, the V8 benchmark uses this:

    // To make the benchmark results predictable, we replace Math.random
    // with a 100% deterministic alternative.
    Math.random = (function() {
      var seed = 49734321;
      return function() {
        // Robert Jenkins' 32 bit integer hash function.
        seed = ((seed + 0x7ed55d16) + (seed << 12))  & 0xffffffff;
        seed = ((seed ^ 0xc761c23c) ^ (seed >>> 19)) & 0xffffffff;
        seed = ((seed + 0x165667b1) + (seed << 5))   & 0xffffffff;
        seed = ((seed + 0xd3a2646c) ^ (seed << 9))   & 0xffffffff;
        seed = ((seed + 0xfd7046c5) + (seed << 3))   & 0xffffffff;
        seed = ((seed ^ 0xb55a4f09) ^ (seed >>> 16)) & 0xffffffff;
        return (seed & 0xfffffff) / 0x10000000;
      };
    })();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just trying to implement a simple audit logging solution with Grails 2.0.2 and it
I'm trying to implement a simple horizontal navigation menu that just shows a single
I'm trying to implement chained filter dropdown using just javascript - jquery. The solution
Am I doing this right? I'm trying to implement a simple countdown timer just
I am just trying to implement a simple web server in C++. For that
I'm trying to implement a simple and advanced search which lets me just type
Trying to implement 3-layer (not: tier, I just want to separate my project logically,
I'm trying to implement a tab menu just like the one in Stack Overflow.
I´ve just started learning GWT and I´m trying to implement http://gwt.google.com/samples/Showcase/Showcase.html#!CwFileUpload and but failing
I'm trying to implement paging in a custom ListAdapter. Right now I'm just making

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.