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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:38:59+00:00 2026-06-14T12:38:59+00:00

I am trying to implement Mersenne Twister algorithm in PHP. I have taken the

  • 0

I am trying to implement Mersenne Twister algorithm in PHP. I have taken the Javascript implementation from http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/JAVASCRIPT/java-script.html

I have almost made a line to line conversion from the above js code. But, the random number generated for a given seed is different in PHP.

Are there any specific steps to be followed when implementing in PHP (Choosing datatypes etc) ?

Code snippet as below

/************* PHP ***************************/


<?php

require_once "mersenne_twister.php";
use mersenne_twister\twister;

$range = array(1,2,3,5,6,7,8,9,12,13,15);
$twister1 = new twister(1347299472.0059);
$t1 =  $twister1->int32()* (1.0 / 4294967296.0) ;
$foo = $t1 * count($range);
echo $foo;


/************* Javascript ***************************/

var seed = 1347299472.0059;
var range = [1,2,3,5,6,7,8,9,12,13,15];// the numbers to chose from
var foo = Math.floor(genrand_float(range ) * range .length);
document.write(foo);

$twister1->int32() * (1.0 / 4294967296.0) and genrand_float(range) gives different output.

Thanks,

  • 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-14T12:39:00+00:00Added an answer on June 14, 2026 at 12:39 pm

    The mt_rand() function already implements the Mersenne Twister algorithm, there’s no need to write your own version.

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

Sidebar

Related Questions

I have this weird kind of error. I am trying implement basic Euclidean algorithm
Trying to implement Ryan's JS implementation of the facebook login, via his Railscast: http://railscasts.com/episodes/360-facebook-authentication
I'm trying implement A* Start path finding in my games(which are written with JavaScript,
Trying to implement NSCopying for the first time, and I have a question about
I am trying implement Unblock me Puzzle. i want to change image position from
Just trying to implement these buttons at the moment: http://web.archive.org/web/20110721191046/http://particletree.com/features/rediscovering-the-button-element/ Can't decide which to
Trying to implement what I thought was a simple concept. I have a user
Trying to implement this gallery on my website. http://coffeescripter.com/code/ad-gallery/ It is noted in the
Trying to implement the following structure from c to use NSArray in objective-c: In
Trying to implement the decorator pattern in C# from the code in the Head

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.