GithubHelp home page GithubHelp logo

js-tinymt's Introduction

js-tinymt

Build Status npm version

The JavaScript implements of TinyMT for Pokémon RNG.

⚠️ Note ⚠️

This library is not designed for common use, but for Pokémon RNG. If you want to use for simulation and numerical analysis and so on, I recommend other library.

Installation

$ npm install @mizdra/tinymt -S
# or
$ yarn add @mizdra/tinymt

Usage

import * as assert from 'assert'
import { Tinymt32 } from '@mizdra/tinymt'

function u32 (num) {
  return num >>> 0
}
const param: Tinymt32.Param = {
  mat1: 0x8F7011EE,
  mat2: 0xFC78FF1F,
  tmat: 0x3793fdff,
}
const seed = 1
const status = [0xCCA24D8, 0x11BA5AD5, 0xF2DAD045, 0xD95DD7B2]

// Tinymt32.fromSeed(param, seed)
const rng1 = Tinymt32.fromSeed(param, seed)
assert(u32(rng1.gen()) === 2545341989)
assert(u32(rng1.gen()) === 981918433)
assert.deepEqual(
  [...Array(2)].map((_) => u32(rng1.gen())),
  [3715302833, 2387538352],
)

// Tinymt32.fromStatus(param, status)
const rng2 = Tinymt32.fromStatus(param, status)
rng2.nextState()
assert(u32(rng2.temper()) === 2545341989)
assert(u32(rng2.gen()) === 981918433)
assert(u32(rng2.temper()) === 981918433)
for (let i = 0; i < 2; i++) { rng2.nextState() }
assert.deepEqual(
  rng1.status().map(u32),
  rng2.status().map(u32),
)

Suppoerted Feature of MersenneTwister-Lab/TinyMT

  • tinymt32
    • tinymt32_next_state
    • tinymt32_temper
    • tinymt32_generate_uint32
    • tinymt32_generate_float
    • tinymt32_generate_float01
    • tinymt32_generate_float12
    • tinymt32_generate_floatOC
    • tinymt32_generate_floatOO
    • tinymt32_generate_32double
  • tinymt64
    • tinymt64_next_state
    • tinymt64_temper
    • tinymt64_generate_uint64
    • tinymt64_generate_double
    • tinymt64_generate_double01
    • tinymt64_generate_double12
    • tinymt64_generate_doubleOC
    • tinymt64_generate_doubleOO

License

js-tinymt's People

Contributors

mizdra avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.