npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dsfmt-js-lib

v0.1.3

Published

Double precision SIMD-oriented Fast Mersenne Twister for Nodejs

Downloads

7

Readme

安全的随机数生成

base on

Mersenne Twister算法译为马特赛特旋转演算法,是伪随机数发生器之一, 其主要作用是生成伪随机数。此算法是Makoto Matsumoto (松本)和 Takuji Nishimura (西村)于1997年开发的,基于有限二进制字段上的 矩阵线性再生。可以快速产生高质量的伪随机数,修正了古老随机数产生算 法的很多缺陷。算法原理

need nodejs version >= 6

install

npm install dsfmt-js-lib --save

usage

var dsfmt = require('dsfmt-js-lib');

// 编译 dSFMT 时使用的参数
dsfmt.DSFMT_MEXP;

// 使用自定义的种子
var seed = 1;
var mt = dsfmt.create(seed);

// 使用生成的安全种子
var mt = dsfmt.create();

// retern [0,1), 这两个函数功能相同
mt.next();
mt.random();

DSFMT_MEXP

生成随机数会重复的次数=2^DSFMT_MEXP, 如果 DSFMT_MEXP=512, 大概的重复周期为 (13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084096) 默认编译参数 DSFMT_MEXP=19937 足够生成不重复的随机数.

改变 DSFMT_MEXP 的方法: 修改 binding.gyp 中 targets.defines.DSFMT_MEXP 并重新编译. 运行测试程序查看输出.

可选的 DSFMT_MEXP: 521, 1279, 2203, 4253, 11213, 19937, 44497, 86243, 132049, 216091

自动生成的种子

在创建 dsfmt 对象时没有指定种子参数, 则会自动生成一个种子, 这个种子与进程id, 时间, 内存状态等相关, 足够复杂而难以预测, 推荐使用自动生成的种子.