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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lazy-random/generators-math-random2

v2.0.1

Published

以瀏覽器/Node.js 原生 Math.random 為亂數來源 (Random Number) 的亂數產生器 (Random Number Generator)

Readme

@lazy-random/generators-math-random2

以瀏覽器/Node.js 原生 Math.random 為亂數 (Random Number) 來源的亂數產生器 (Random Number Generator),隸屬 @lazy-random 系列套件。

本套件將原生 Math.random 包裝為 RNGMathRandom2 類別,繼承自 @lazy-random/generators-function 的 RNGFunction,讓「以函式 (Function) 為基礎」的亂數來源能與其他演算法共用同一套介面。

特色 (Features)

  • 直接包裝原生 Math.random,無須設定種子 (Seed) 即可使用
  • 繼承 RNGFunction,可與 @lazy-random 系列的其他產生器互換使用
  • 同時提供 CommonJS (dist/index.cjs) 與 ECMAScript Module (dist/index.esm.mjs) 兩種輸出,並附帶型別宣告 (dist/index.d.ts)

安裝 (Installation)

yarn add @lazy-random/generators-math-random2
yarn-tool add @lazy-random/generators-math-random2
yt add @lazy-random/generators-math-random2

使用方式 (Usage)

import RNGMathRandom2 from '@lazy-random/generators-math-random2'

const rng = new RNGMathRandom2()

console.log(rng.name) // 'math-random2'

若要沿用指定的亂數來源函式,可在建構子 (Constructor) 的第一個參數傳入:

import RNGMathRandom2 from '@lazy-random/generators-math-random2'

const rng = new RNGMathRandom2(myRandomFunction)

API 文件 (API Documentation)

class RNGMathRandom2

繼承自 RNGFunction<typeof _MathRandom>,預設以 @lazy-random/original-math-random 提供的 _MathRandom 作為亂數來源。

constructor(seed?, opts?, ...argv)

| 參數 (Parameter) | 型別 (Type) | 說明 (Description) | | --- | --- | --- | | seed | typeof _MathRandom | 亂數來源函式 (Random source function);省略或傳入假值 (Falsy) 時,回退為預設的 _MathRandom | | opts | 未限定 | 傳給基類 RNGFunction 的選項 (Options) | | ...argv | 未限定 | 其餘參數,原樣轉交基類 (Forwarded to the base class) |

get name(): string

回傳產生器名稱 (Generator Name) 'math-random2',用於除錯或辨識目前使用的演算法。

預設匯出 (Default Export)

RNGMathRandom2 同時為具名匯出 (Named Export) 與預設匯出。

開發 (Development)

專案根目錄使用 pnpm + lerna 的 monorepo 結構,本套件常見指令:

pnpm run build   # 以 tsdx 建置 dist
pnpm run test    # 執行測試
pnpm run lint    # 執行 ESLint

變更日誌 (Changelog)

請見 CHANGELOG.md。

相關資源 (Related Resources)